Thursday, 5 September 2013

WCF Service. How to return HTTP 500 response

WCF Service. How to return HTTP 500 response

I have a WCF service which access the registry and return the value. I
would like to return a HTTP 500 response in certain cases for e.g. when I
get null values returned from the registry without any exception. Here is
my code. Instead of returning "null" string I want to return HTTP 500
response.
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";
}
}
how can I create this HTTP 500 response to return to the client?
Please help.

No comments:

Post a Comment