How to add <wsdl:fault> to a single operation in wsdl?
-
Monday, April 11, 2011 11:53 AM
Hi All,
We have added an operation to existing web service. The consumer of this wsdl needs to parse the <wsdl:fault> as part of their exception handling mechanism for this operation while the wsdl generated does not have <wsdl:fault>. There are few considerations:
- The detail node under fault is customized to have 3 child nodes: message, errorID, description.
- Namespace for the Response generated for SoapException is different from the namespace for Success Response.
Here is an example of a successful response :-
<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>
<MyOperResponse xmlns="http://something.com/MyWS">
<MyOperResult>
<attr1/>
.
.
<attr2></attr2>
</MyOperResult>
</MyOperResponse>
</soap:Body>
</soap:Envelope>Here is an example of a response with SOAP Exception :-
<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:Server</faultcode>
<faultstring>System.Web.Services.Protocols.SoapException: Not Found
****Stack Trace****
<detail>
<message>Not Found</message>
<description>Not Found</description>
<errorId>1</errorId>
</detail>
</soap:Fault>
</soap:Body>
</soap:Envelope>- fault is required only for new operation, rest of the wsdl will have just input and output.
- Cannot switch to WCF.
We tried a workaround by adding fault manually to the wsdl as below:
WSDL Definition update:-
<wsdl:definitions xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tns="http://something.com/MyWS" xmlns:s="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/" xmlns:http="http://schemas.xmlsoap.org/wsdl/http/" targetNamespace="http://something.com/MyWS" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:env="http://schemas.xmlsoap.org/soap/envelope/" >Element Definition Added:-
<s:schema elementFormDefault="qualified" targetNamespace="http://schemas.xmlsoap.org/soap/envelope/">
<s:element name="MyWSFault" type="env:Fault"/>
<s:complexType final="extension" name="Fault">
<s:annotation>
<s:documentation>Fault reporting structure</s:documentation>
</s:annotation>
<s:sequence>
<s:element maxOccurs="1" minOccurs="0" name="faultcode" type="s:string"/>
<s:element maxOccurs="1" minOccurs="0" name="faultstring" type="s:string"/>
<s:element maxOccurs="1" minOccurs="0" name="faultactor" type="s:anyURI"/>
<s:element maxOccurs="1" minOccurs="0" name="detail">
<s:complexType>
<s:sequence>
<s:element maxOccurs="1" minOccurs="0" name="message" type="s:string"/>
<s:element maxOccurs="1" minOccurs="0" name="description" type="s:string"/>
<s:element maxOccurs="1" minOccurs="0" name="errorId" type="s:string"/>
</s:sequence>
</s:complexType>
</s:element>
</s:sequence>
</s:complexType>
</s:schema>Message Definition Added:-
<wsdl:message name="MyOperFault">
<wsdl:part name="errorInfo" element="tns:MyWSFault" />
</wsdl:message>Operation Definition Updated:-
<wsdl:operation name="MyOper">
<wsdl:input message="tns:MyOperSoapIn" />
<wsdl:output message="tns:MyOperSoapOut" />
<wsdl:fault message="tns:MyOperFault" name="MyOperFault" />
</wsdl:operation>Binding Element Updated:-
<wsdl:operation name="MyOper">
<soap:operation soapAction="http://something.com/MyWS/MyOper" style="document" />
<wsdl:input>
<soap:body use="literal" />
</wsdl:input>
<wsdl:output>
<soap:body use="literal" />
</wsdl:output>
<wsdl:fault name="MyOperFault">
<soap:fault name="MyOperFault" use="literal" />
</wsdl:fault>
</wsdl:operation>
Even after these changes in WSDL, consumer is not able to parse the fault. Are we doing somthing wrong or missing something?If there is some other way by which we can add fault just to the response for new operation, would also help?
Thanks!
All Replies
-
Thursday, October 06, 2011 7:08 AM
Hi,
Use this example of a typical WSDL that contains fault messages to find out how SOAP faults are defined in a WSDL file.
The following example of a typical WSDL file contains a port type called “MathOps”. There is an operation called “div” that has three possible fault messages called “DivByZeroStruct”, “SpecialDetailStruct” and “OutOfBoundStruct”.
<wsdl:portType name="MathOps">
<wsdl:operation name="div">
<wsdl:input message="impl:divRequest" name="divRequest"/>
<wsdl:output message="impl:divResponse" name="divResponse"/>
<wsdl:fault message="impl:DivByZeroStruct" name="DivByZeroStruct"/>
<wsdl:fault message="impl:SpecialDetailStruct" name="SpecialDetailStruct"/>
<wsdl:fault message="impl:OutOfBoundStruct" name="OutOfBoundStruct"/>
</wsdl:operation>
</wsdl:portType> -
Thursday, October 06, 2011 4:25 PMModerator
ASMX web services do not have proper support for SOAP Faults.
This is yet another reason to use WCF, which has full support for SOAP Faults.
John Saunders
WCF is Web Services. They are not two separate things.
Use WCF for All New Web Service Development, instead of legacy ASMX or obsolete WSE
Use File->New Project to create Web Service Projects -
Wednesday, February 15, 2012 1:47 AM
I'm getting the same error:
System.Web.Services.Protocols.SoapException: Not found
at System.Web.Services.Protocols.SoapHttpClientProtocol.ReadResponse(SoapClientMessage message, WebResponse response, Stream responseStream, Boolean asyncCall)
at System.Web.Services.Protocols.SoapHttpClientProtocol.Invoke(String methodName, Object[] parameters)
Unfortunately I can't use WCF as only .NET 2.0 is available on the clients at the moment. Strangely this program that calls a WCF basicHttpBinding, works on other clients. The "not found" error simply isn't good enough for troubleshooting.
-
Wednesday, February 15, 2012 2:43 AMModeratorYou appear to have replied to the wrong thread. This thread doesn't mention a "not found" error.
John Saunders
WCF is Web Services. They are not two separate things.
Use WCF for All New Web Service Development, instead of legacy ASMX or obsolete WSE
Use File->New Project to create Web Service Projects -
Wednesday, February 15, 2012 2:45 AM
No - it's there - see the fault soap detail at the top:
<soap:Fault>
<faultcode>soap:Server</faultcode>
<faultstring>System.Web.Services.Protocols.SoapException: Not Found
****Stack Trace****
<detail>
<message>Not Found</message>
<description>Not Found</description>
<errorId>1</errorId>
</detail>
</soap:Fault>I'm debugging this error now - trying to work out what's so unique about this client vs others...
-
Wednesday, February 15, 2012 3:08 AM
In any case, the error was correctly passed-through the soap layer - just the text only - the error itself was a WMI error thrown by ManagementObjectServer.Get() (seems the WMI Service is failing for this client).
My recommendation would be to catch all errors on the server-side and wrap them with some context text so you know what's happening.
-
Wednesday, February 15, 2012 3:45 AMModerator
Ok, but you missed the point of the thread. The OP was not able to get a <wsdl:fault> element added to his WSDL file. You seem to be having some sort of "not found" error. Those are unrelated problems.
In fact, the solution to the OP's problem is simply to use WCF, which supports SOAP faults. The legacy ASMX technology does not support faults. It will never add a <wsdl:fault> to the WSDL that it generates on the server side, and a web reference (the client side of ASMX) will not generate unique exceptions corresponding to any faults found in the WSDL.
In WCF, it just works.
John Saunders
WCF is Web Services. They are not two separate things.
Use WCF for All New Web Service Development, instead of legacy ASMX or obsolete WSE
Use File->New Project to create Web Service Projects -
Wednesday, February 15, 2012 4:08 AM
I agree it's unrelated now that I know what caused it, but I have exactly the same fault string "System.Web.Services.Protocols.SoapException: Not Found" and my issue seemed related to ASMX for which this forums pertains to.

