我正在使用C#,ASP.NET开发一个Web服务。默认情况下,当我的webservice抛出异常时,使用
throw new SoapException("ERROR_MESSAGE", SoapException.ClientFaultCode);
这将输出以下xml:
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<soap:Body>
<soap:Fault>
<faultcode>soap:Client</faultcode>
<faultstring>ERROR_MESSAGE</faultstring>
<detail/>
</soap:Fault>
</soap:Body>
</soap:Envelope>
但是,我必须实现使用不同xml的自定义错误类型:
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body xmlns:cst="http://cust.om/Namespace">
<cst:Fault>
<cst:errorMessage>ERROR_MESSAGE</cst:errorMessage>
</cst:Fault>
</soap:Body>
</soap:Envelope>
他们希望这个错误类型也出现在由http-GETting?wsdl生成的wsdl文件中,作为元素出现在那里。
这甚至可能吗?好吧,一切都可以通过用替换的字符串重写现有的流来实现,但我更喜欢那种残酷的方法。此外,这种修复不会导致元素出现在自动生成的wsdl规范中。