我有一个 REST 服务,我想有一个帮助类来处理异常
我的代码如下所示:
[WebGet(UriTemplate = "/Test/{param}")]
public Stream Test(string param)
{
if (param == "Ok")
return Process(param);
else
{
RESTException(System.Net.HttpStatusCode.BadRequest, "Param not ok");
return null;
}
}
private void RESTException(System.Net.HttpStatusCode httpStatusCode, string message)
{
OutgoingWebResponseContext response = WebOperationContext.Current.OutgoingResponse;
response.StatusCode = httpStatusCode; // or anything you want
response.StatusDescription = message;
}
我从浏览器测试,但是当我传递错误的参数时,例如
http://myaddress/Service/Test/badparam
浏览器中没有任何显示。
我的代码有什么问题?