抛出SoapException不会返回有效的SOAP响应 [英] Throwing a SoapException does not return a valid SOAP response

查看:90
本文介绍了抛出SoapException不会返回有效的SOAP响应的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在一个旧的网站上工作.它正在调用ASP.Net Web服务(旧的.asmx文件).每当Web服务中发生异常时,它将抛出SoapException.客户端捕获了此异常,但无法对其进行解析.

I'm working on an old web site. It is calling an ASP.Net web service (old .asmx files). Whenever an exception happens in the web service, it will throw a SoapException. The client catches this exception but is not able to pars it.

我正在使用 Fiddler SOAP UI 查看SOAP请求和响应,并正在阅读本文

I'm viewing the SOAP request and response using both Fiddler and SOAP UI and reading this article http://msdn.microsoft.com/en-us/library/aa480514.aspx I expect to get the response in the following format:

<soap:Fault>
<faultcode>soap:Server</faultcode>    
<faultstring>Server was unable to process request. Something bad happened</faultstring>
<detail />

但是,我得到以下答复:

However, I'm just getting the following response:

HTTP/1.1 500 Internal Server Error
Server: ASP.NET Development Server/10.0.0.0
Date: Thu, 12 Jun 2014 05:27:14 GMT
X-AspNet-Version: 2.0.50727
Cache-Control: private
Content-Type: text/plain; charset=utf-8
Content-Length: 164
Connection: Close

System.Web.Services.Protocols.SoapException: Something bad happened
   at WebService1.Service1.HelloWorld() in ...

我相信这是客户端无法处理异常的原因.

Which I believe is the reason the client can't process the exception.

即使在示例Hello World Web服务中,也会发生这种情况.

This happens even in a sample Hello World web service.

有什么问题吗?

更新:当我调用不会引发异常的Web服务方法时,我将获得以下格式的响应:

UPDATE: When I call my web service method that does NOT throw exception, I will get response in the following format:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ords="http://mydomain.com/">
   <soapenv:Header/>
   <soapenv:Body>
      ...
   </soapenv:Body>
</soapenv:Envelope>

这就是我抛出SoapException的方式:

This is how I throw the SoapException:

[WebMethod]
public string HelloWorld()
{
     throw new SoapException("Something bad happened", SoapException.ClientFaultCode);
     //return "Hello World";
}

推荐答案

我在Web服务web.config文件中发现了一些根本不使用的httpHandlers和模块.除去这些问题后,现在我在响应中得到了正确的XML SOAP错误.

I found some httpHandlers and modules in the web service web.config files that were not used at all. Removing those fixed the problem and now I'm getting the correct XML SOAP fault in the response.

这篇关于抛出SoapException不会返回有效的SOAP响应的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆