WebFaultException 传回 XML 消息而不是字符串?
在我的 RESTful 服务层中,出现的任何异常都会被捕获为错误异常。在该FaultException 中,有一条自定义XML 消息,其中包含
、
和
。我将异常重新打包为 WebFaultException,这样我就可以将响应标头的 HttpStatusCode 设置为 400、401、404 等。
但是,我不想使用 WebFaultException
。我希望该消息也是 XML 消息。
有人知道如何设置响应消息的 HttpStatusCode 并设置 XML 消息吗?我正在使用 Fiddler 检查我的响应标头以及从服务发出的任何消息。
In my RESTful services layer, any exceptions that bubble up to me are caught as Fault Exceptions. Within that FaultException, there's a custom XML message that contains <errorNumber>
, <errorCode>
and a <message>
. I re-package the exception as a WebFaultException so I can set the HttpStatusCode for the response header to 400, 401, 404, etc.
However, I don't want to use WebFaultException<string>(string message, HttpStatusCode code)
. I want the message to also be an XML message.
Anyone seen how to set the HttpStatusCode of the response message AND set an XML message? I'm using Fiddler to examine my response headers and any messages that come up from the service.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
为了解决这个问题,我所做的就是创建一个具有简单属性的新类
MyException
并使用WebFaultException
并且它工作得很好。我在以下链接中找到了解决方案: http://www.c -sharpcorner.com/UploadFile/ankithakur/ExceptionHandlingWCF12282007072617AM/ExceptionHandlingWCF.aspxWhat I did to get around this was create a new class
MyException
with simple properties and usedWebFaultException<MyException>
and it works nicely. I found the solution at the following link: http://www.c-sharpcorner.com/UploadFile/ankithakur/ExceptionHandlingWCF12282007072617AM/ExceptionHandlingWCF.aspx