WCF WebApi HttpResponseException 问题
我试图抛出 HttpResponseException(HttpStatusCode.NotFound)
并且收到以下错误
此异常的 Response 属性返回的响应消息应立即返回给客户端。不需要进一步处理请求消息。
我已经删除了方法中的所有代码,我只是抛出这样的异常
[WebGet]
public MyData Get()
{
throw new HttpResponseException(HttpStatusCode.NotFound);
}
如果我更改方法以返回 HttpResponseMessage
我可以让它正常工作,但是它不能解决问题如果无法抛出 HttpResponseException
,我就无法让我的身份验证操作处理程序正常工作。
I am trying to throw an HttpResponseException(HttpStatusCode.NotFound)
and I am getting the following error
The response message returned by the Response property of this exception should be immediately returned to the client. No further handling of the request message is required.
I have removed all of the code in my method and I am just throwing the exception like this
[WebGet]
public MyData Get()
{
throw new HttpResponseException(HttpStatusCode.NotFound);
}
If I change my method to return a HttpResponseMessage
I can get it to work correctly, however it does not solve the issue and I am unable to get my authentication operation handler to work without being able to throw a HttpResponseException
.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试使用
WebFaultException
返回 HTTP 状态WCF 中的代码...Try using a
WebFaultException
for returning HTTP Status codes in WCF...