4
我正在使用舊的Web站點。它調用一個ASP.Net Web服務(舊的.asmx文件)。只要Web服務發生異常,它就會拋出SoapException。客戶端捕獲該異常,但無法對其進行分析。拋出SoapException不會返回有效的SOAP響應
我觀察使用這兩種提琴手和SOAP UI和閱讀這篇文章http://msdn.microsoft.com/en-us/library/aa480514.aspx我期望能獲得以下格式的響應SOAP請求和響應:
<soap:Fault>
<faultcode>soap:Server</faultcode>
<faultstring>Server was unable to process request. Something bad happened</faultstring>
<detail />
不過,我只是得到以下回應:
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 ...
我認爲這是客戶端無法處理異常的原因。
甚至在示例Hello World Web服務中也會發生這種情況。
什麼可能是錯的?
更新:當我調用不拋出異常我的Web服務方法,我會在下面的形式迴應:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ords="http://mydomain.com/">
<soapenv:Header/>
<soapenv:Body>
...
</soapenv:Body>
</soapenv:Envelope>
這是我扔的SoapException:
[WebMethod]
public string HelloWorld()
{
throw new SoapException("Something bad happened", SoapException.ClientFaultCode);
//return "Hello World";
}
你看看這個線程:http://stackoverflow.com/questions/17449035/throwing-soapexception-in-net-web-service? – qbik