访问出错时怎么能返回给客户端带Fault标签的信息?
A公司是客户端,B公司是服务器端。
我们在给B公司做web service程序。
A公司发送给信息,访问B公司的web service提供的接口函数,
比如说,函数WsIFfnc(),接口函数的返回值类型是String型。
到这为止,通过写代码都可以实现。
但现在A公司说,他们跟其他公司的web service的时候,如果出错。
返回的不是String型。是这样的信息。
HTTP/1.0 500 Internal Server Error Content-Type:text/xml;charset="utf-8" content-Length:nnnnn <SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"> <SOAP-ENV:Body> <SOAP-ENV:Fault> <faultcode>Client.AuthenticationFailure </faultcode> <faultstring>认证失败 </faultstring> <faultactor>http://www.partner.com/gateway </faultactor> </SOAP-ENV:Fault> </SOAP-ENV:Body> </SOAP-ENV:Envelope>
[WebMethod] public string HelloWorld() { Exception ex = new Exception("this is error"); throw ex; }