Welcome to Windows Communication Foundation (WCF)
Top Tasks :

WCF Team Bloggers

A Trick with Faults (Discussion)

The code yesterday was meant to motivate a side-discussion on how faults get generated and handled between the server and client proxy. If you tried running that sample, then you would have seen that despite the FaultException being thrown on the service, the service call completes normally. The return value of the service call is a fault message. If you've been writing your contracts with typed messages instead of the raw Message type, then this is the opposite behavior to what you're used to seeing. Using the same pattern for exception handling doesn't work between typed and untyped messages. This is particularly messy when you have a mix of typed and untyped operation contracts on the same service because it requires some duplicated logic for handling errors. However, I think that would be a pretty rare service design. There are four cases that I think are interesting to look at so that you can see the different fault behaviors that could occur. Untyped fault exception with an untyped message contract The basic case from yesterday is to receive a fault message. < s:Envelope xmlns:s ="http://www.w3.org/2003/05/soap-envelope" xmlns:a ="http://www.w3.org/2005/08/addressing" > < s:Header > < a:Action s:mustUnderstand ="1" > http://www.w3.org/2005/08/addressing/soap/fault </ a:Action > < a:RelatesTo > urn:uuid:dd129ffe-a8ff-4a70-ad6f-ad48085e94e8 </ a:RelatesTo > < a:To s:mustUnderstand ="1" > http://www.w3.org/2005/08/addressing/anonymous </ a:To > </ s:Header > < s:Body > < s:Fault > < s:Code > < s:Value > s:Sender </ s:Value > </ s:Code > < s:Reason > < s:Text xml:lang ="en-US" > boo! </ s:Text > </ s:Reason > </ s:Fault > </ s:Body > </ s:Envelope > Typed fault exception with an untyped message contract I'm just changing the FaultException to a FaultException here, although you can have any type you want for the fault detail. This changes the contents of the fault message but not the code path. Note that the action is different in addition to the detail section to match the parameterized type. < s:Envelope xmlns:s ="http://www.w3.org/2003/05/soap-envelope" xmlns:a ="http://www.w3.org/2005/08/addressing" > < s:Header > < a:Action s:mustUnderstand ="1" > http://tempuri.org/IService/VerbStringFault </ a:Action > < a:RelatesTo > urn:uuid:49ee87c7-691f-48c4-86ea-bb172c99294d </ a:RelatesTo > < Read More...
Published Wednesday, February 28, 2007 8:00 AM by Nicholas Allen's Indigo Blog
Filed under: , ,

Comments

No Comments
Anonymous comments are disabled

Copyright © 2006 Microsoft Corporation. All Rights Reserved. | Terms of Use | Privacy Statement | Contact Us