Note that there are some explanatory texts on larger screens.

plurals
  1. POCan't catch Java custom faults on WCF client
    primarykey
    data
    text
    <p>The problem is similar to this question: <a href="https://stackoverflow.com/questions/864800/does-wcf-faultexceptiont-support-interop-with-a-java-web-service-fault">Does WCF FaultException&lt;T&gt; support interop with a Java web service Fault</a>. However, in my case, the custom fault is indeed returned from the service.</p> <p>Tricky to explain this but here it goes:</p> <p>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:</p> <pre><code>&lt;xs:complexType name="ServiceFault"&gt; &lt;xs:annotation&gt; &lt;xs:documentation&gt;On service error&lt;/xs:documentation&gt; &lt;/xs:annotation&gt; &lt;xs:all&gt; &lt;xs:element name="ErrorCode" type="xs:string"/&gt; &lt;xs:element name="ErrorDescription" type="xs:string"/&gt; &lt;/xs:all&gt; &lt;/xs:complexType&gt; </code></pre> <p>This ServiceFault is used for all more specific custom faults (eg. MyMethodFault) so they all get the ErrorCode and ErrorDescription properties, like so:</p> <pre><code>&lt;xs:element name="MyMethodFault" type="ServiceFault"&gt; &lt;xs:annotation&gt; &lt;xs:documentation&gt;On error in MyMethod&lt;/xs:documentation&gt; &lt;/xs:annotation&gt; &lt;/xs:element&gt; </code></pre> <p>Next, the WSDL-messages for the faults are defined, like this:</p> <pre><code>&lt;wsdl:message name="MyMethodFault"&gt; &lt;wsdl:part element="tns:MyMethodFault " name="MyMethodFault"&gt; &lt;/wsdl:part&gt; </code></pre> <p>And finally, the operations are defined with those faults, like this:</p> <pre><code>&lt;wsdl:fault message="tns:MyMethodFault" name="MyMethodFault"&gt; </code></pre> <p>Looks good to me, so far. And at runtime, the service neatly returns the faults in the detail SOAP-tag, like this:</p> <pre><code>&lt;ns2:MyMethodFault xmlns:ns2="urn:salessystem:entity:MyService:v1.0"&gt; &lt;ns2:ErrorCode&gt;1000&lt;/ns2:ErrorCode&gt; &lt;ns2:ErrorDescription&gt;TheErrorDescr&lt;/ns2:ErrorDescription&gt; &lt;/ns2:MyMethodFault&gt; </code></pre> <p>However, SvcUtil didn’t generate the more <strong>specific</strong> custom faults, only the <strong>ServiceFault</strong>. This is the only mentioning of MyMethodFault in the service reference:</p> <pre><code>[OperationContractAttribute(Action = "", ReplyAction = "*")] [FaultContractAttribute(typeof(sale...ServiceFault), Action="", Name="MyMethodFault")] [ServiceKnownTypeAttribute(typeof(ServiceFault))] MyMethodResponse MyMethod(MyMethodRequest1 request); </code></pre> <p>So, here is the problem: </p> <p>Since MyMethodFault doesn’t exist I can’t catch <code>FaultException&lt;MyMethodFault&gt;.</code> And furthermore, WCF won’t map a specific fault like MyMethodFault to a ServiceFault at runtime so exceptions of type <code>FaultException&lt;ServiceFault&gt;</code> are never caught. Hence, I never get the error description.</p> <p>Am I doing something wrong or do I need to tweak the WSDL or the SvcUtil-usage?</p> <p>Hope anyone can understand the question at all :P</p> <p>Thanks, Björn</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload