【问题标题】:How to change SOAPException ResponseCode如何更改 SOAPException 响应代码
【发布时间】:2011-06-15 00:29:39
【问题描述】:

我正在使用SoapException 来处理我的 Web 服务中的无效输入和所有其他类型的异常处理。它工作正常,我能够格式化并向客户返回正确的信息。我正在遵循类似于此处解释的方法 http://www.codinghorror.com/blog/2004/08/throwing-better-soap-exceptions.html

现在我想更改它在SoapException 发生时返回的响应代码(ResponseCode: 500 Internal Server Error)。

SoapException 发生时,除了我自己的自定义XML 数据之外,以下是默认响应代码。我想将ResponseCode 更改为 200 .. 是否可能以及如何?

ResponseCode: 500 (Internal Server Error)  
Connection:Close  
Content-Length:494  
Cache-Control:private  
Content-Type:text/xml; charset=utf-8  
Date:Tue, 25 Jan 2011 06:59:30 GMT  
Server:ASP.NET Development Server/8.0.0.0  
X-AspNet-Version:2.0.50727

【问题讨论】:

  • 找到答案 ((System.Web.HttpContext)(System.Runtime.Remoting.Messaging.CallContext.HostContext)).Response.StatusCode = 200;
  • @Ariz:如果这是您选择的解决方案,那么您选择了违反 SOAP 标准。代码必须是 500。
  • 由于某些浏览器不会将异常内容转发到消耗 webmethod 的 flash,我也想将 statusCode 更改为 200。但是,该解决方案对我不起作用。 ((System.Web.HttpContext)(System.Runtime.Remoting.Messaging.CallContext.HostCont‌​ext)).Response.StatusCode = 200; throw new SoapException(); 仍然返回响应码 500

标签: c# asp.net web-services exception-handling soapexception


【解决方案1】:

根据 WS-I Basic profile,支持 John Sauders 的上述警告:

“如果响应消息是 SOAP 错误,则 R1126 实例必须使用“500 内部服务器错误”HTTP 状态代码。”

http://www.ws-i.org/Profiles/BasicProfile-1.0-2004-04-16.html#refinement16488480

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多