The problem is similar to this question: Does WCF FaultException<T> support interop with a Java web service Fault. However, in my case, the custom fault is indeed returned from the service.
Tricky to explain this but here it goes:
From a new WCF client, I’m calling an existing Java web service (that has worked well for years with other kinds of clients). The service XSD defines one custom fault ServiceFault:
<xs:complexType name="ServiceFault">
<xs:annotation>
<xs:documentation>On service error</xs:documentation>
</xs:annotation>
<xs:all>
<xs:element name="ErrorCode" type="xs:string"/>
<xs:element name="ErrorDescription" type="xs:string"/>
</xs:all>
</xs:complexType>
This ServiceFault is used for all more specific custom faults (eg. MyMethodFault) so they all get the ErrorCode and ErrorDescription properties, like so:
<xs:element name="MyMethodFault" type="ServiceFault">
<xs:annotation>
<xs:documentation>On error in MyMethod</xs:documentation>
</xs:annotation>
</xs:element>
Next, the WSDL-messages for the faults are defined, like this:
<wsdl:message name="MyMethodFault">
<wsdl:part element="tns:MyMethodFault " name="MyMethodFault">
</wsdl:part>
And finally, the operations are defined with those faults, like this:
<wsdl:fault message="tns:MyMethodFault" name="MyMethodFault">
Looks good to me, so far. And at runtime, the service neatly returns the faults in the detail SOAP-tag, like this:
<ns2:MyMethodFault xmlns:ns2="urn:salessystem:entity:MyService:v1.0">
<ns2:ErrorCode>1000</ns2:ErrorCode>
<ns2:ErrorDescription>TheErrorDescr</ns2:ErrorDescription>
</ns2:MyMethodFault>
However, SvcUtil didn’t generate the more specific custom faults, only the ServiceFault. This is the only mentioning of MyMethodFault in the service reference:
[OperationContractAttribute(Action = "", ReplyAction = "*")]
[FaultContractAttribute(typeof(sale...ServiceFault), Action="", Name="MyMethodFault")]
[ServiceKnownTypeAttribute(typeof(ServiceFault))]
MyMethodResponse MyMethod(MyMethodRequest1 request);
So, here is the problem:
Since MyMethodFault doesn’t exist I can’t catch FaultException<MyMethodFault>.
And furthermore, WCF won’t map a specific fault like MyMethodFault to a ServiceFault at runtime so exceptions of type FaultException<ServiceFault>
are never caught. Hence, I never get the error description.
Am I doing something wrong or do I need to tweak the WSDL or the SvcUtil-usage?
Hope anyone can understand the question at all :P
Thanks, Björn