WebOperationContext.Current.OutgoingResponse.StatusCode is not working
In WCF REST API I would like to set own StatusCode for some reason -
WebOperationContext.Current.OutgoingResponse.StatusCode =
HttpStatusCode.Forbidden (or any other statuscode)
it doesn't work at all as in the client end : -
using (HttpWebResponse restResponse =
(HttpWebResponse)restRequest.GetResponse())
{
if (restResponse.StatusCode != HttpStatusCode.OK)
{
retVal = String.Format("Request failed. Received HTTP
{0}, Description : {1}", restResponse.StatusCode,
restResponse.StatusDescription);
return retVal;
}
using (var st = restResponse.GetResponseStream())
{
StreamReader sr = new StreamReader(st);
retVal = sr.ReadToEnd();
return retVal;
}
}
but here the restResponse.StatusCode is always HttpStatusCode.OK.
May I know the reason? What is wrong here?
No comments:
Post a Comment