I have to consume to a third-party web service using SOAP. It was easy to get it to work with WCF, but now I have a problem with SOAP faults. The service sends me an incorrect SOAP fault:
<?xml version="1.0" encoding="utf-8" ?>
<SOAP-ENV:Envelope
SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
<SOAP-ENV:Body>
<SOAP-ENV:Fault>
<SOAP-ENV:faultcode>14</SOAP-ENV:faultcode>
<SOAP-ENV:faultstring>Unknown Function</SOAP-ENV:faultstring>
</SOAP-ENV:Fault>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
The error is that the <faultcode>
must not have a namespace:
System.ServiceModel.CommunicationException : Server returned an invalid
SOAP Fault. Please see InnerException for more details.
----> System.Xml.XmlException : Start element 'faultcode' from namespace
'' expected. Found element 'SOAP-ENV:faultcode' from namespace
'http://schemas.xmlsoap.org/soap/envelope/'.
I can't change the original web service - but is there anything in WCF I can use to still handle these fault messages in some way without getting CommunicationException
all the time?
If an error occurs during processing, the response to a SOAP message is a SOAP fault element in the body of the message, and the fault is returned to the sender of the SOAP message.
In a service, use the FaultException class to create an untyped fault to return to the client for debugging purposes. In a client, catch FaultException objects to handle unknown or generic faults, such as those returned by a service with the IncludeExceptionDetailInFaults property set to true .
A SOAP fault is an error in a SOAP (Simple Object Access Protocol) communication resulting from incorrect message format, header-processing problems, or incompatibility between applications.
Yes, but it's not exactly elegant. See the message inspector code at the bottom of this forum post:
http://social.msdn.microsoft.com/Forums/en-US/wcf/thread/435850aa-bf74-4158-a29a-256135207948
Basically, you can take the incoming message and alter it so that it can be handled by WCF.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With