Actions for FaultExceptions
What should I set the action parameter to when creating a FaultException?
There is indeed a pair of overloads for creating fault exceptions that take an action parameter, although most of the overloads lack this.
public FaultException(TDetail detail, FaultReason reason, FaultCode code, string action);
public FaultException(TDetail detail, string reason, FaultCode code, string action);
What does the action parameter actually do? Well, this may or may not be obvious, but setting the action on the fault exception controls the action that is used when sending the fault message. This is the reason why you can't just make up an action here and expect it to work. The receiver is looking for a particular action to reconstitute the fault message to an exception with the appropriate type. If you break the action here, then your typed FaultException turns into an untyped FaultException.
The expected action value for a particular typed FaultException comes from the fault contract. If you just set up the fault contract and don't worry at all about the action when creating fault exceptions, then everything should work. The fault exception will automatically pick up the correct action from the fault contract. The answer then is that you shouldn't set the action parameter at all in most cases.
The default fault contract action is generated by combining
a number of type strings. For instance,
if my service contract is IService, my operation is called Action, and I'm
using a typed FaultException<string> instance, then the default fault
action is <tempuri.org/IService/ActionStringFault>. Similarly, if I'm instead using a typed
FaultException<IList<string>>, then the default fault action is <tempuri.org/IService/ActionIListOf_StringFault>.
You can get as crazy as you want and figure
out what the expected pattern should be for any type. Want to send an IDictionary<IList<string>,
IDictionary<DateTime, string>>?
It will be <tempuri.org/IService/ActionIDictionaryOf_IListOf_String_IDictionaryOf_DateTime_StringFault>.
Of course, you can explicitly put an action
in the fault contract attribute to set this value to anything.
Next time: Transport Encryption and Signing
Comments
Anonymous
February 05, 2007
What's the fastest binding for securely communicating over an intranet? How about if the client and serverAnonymous
February 19, 2007
I haven't forgotten about the goal to put together a table of contents for all of these articles. The