Throwing a SoapException does not return a valid SOAP response

北战南征 提交于 2019-12-10 15:17:00

问题


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.

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.

This happens even in a sample Hello World web service.

What can be wrong?

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>

This is how I throw the SoapException:

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

回答1:


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.



来源:https://stackoverflow.com/questions/24177262/throwing-a-soapexception-does-not-return-a-valid-soap-response

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!