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
ブラウザには何も表示されません。
私のコードの何が問題になっていますか?