我有一個WCF服務,它訪問註冊表並返回值。我想在某些情況下爲HTTP 500返回HTTP 500響應。當我從註冊表返回空值時沒有任何異常。這是我的代碼。而不是返回「空」字符串我想返回HTTP 500響應。WCF服務。如何返回HTTP 500響應
private string baseKey = "SOFTWARE\\Action\\software\\Station";
public string GetCode()
{
string Code;
try
{
using (RegistryKey regKey = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine,
Environment.Is64BitOperatingSystem ? RegistryView.Registry64 : RegistryView.Registry32))
{
using (RegistryKey subKey = regKey.OpenSubKey(baseKey, false))
{
Code = (string)subKey.GetValue("Code");
};
};
return string.IsNullOrEmpty(Code) ? "null" : Code;
}
catch (Exception ex)
{
return "null";
}
}
如何創建HTTP 500響應返回客戶端?
請幫忙。
酷派
HttpStatusCode
枚舉值。非常感謝。 – Newbee