Day 5 – Chapter 3
The third chapter goes into error handling in WCF. The introduction to the problem is short and sweet. You can always throw a new FaultException when you catch an exception in the service itself. This turns your error into a SOAP exception that your application can catch and hadle. This however is only a generic FaultException.
The thing that is really cool is that you can define strongly typed FaultExceptions. You do so by the DataContract format just like any other type. What makes this different is that you can add an attribute to your method definition in the interface that specifies the type of exception that can be generated. For example:
[DataContract]
public class MyException
{
[DataMember]
public string ErrorMessage;
}
now that you have your strongly typed fault, you can add the attribute to the service contract interface:
[FaultContract(typeof(MyException))]
[OperationContract]
public bool MyOperation(…)
So how does your client application know about these error types? Well when you create your proxy class it creates the new fault types. The book has you create the proxy using “svcutil”, the whole process seemed rather manual to me. I’m not going to describe it because then you wouldn’t need to buy the book now would you? Or you could always google it
The next thing discussed is the “includeExceptionDetailInFaults” setting that can be set for the host of your service. This property specifies whether or not the specific exception details will be passed along to the client. I actually already got to deal with this while trying to figure out what I did wrong in Chapter 2 :0) As you may recall… or scroll down to read it ended up being a DLL issue in the EL.
The last two parts of the book would make someones head spin if they did not take … I forget what class it was exactly… but it talks about how a ServiceHost class is really a finite state machine. It can be in one of many states depending on what is going on. Pretty cool diagram in the book
I am really tired right now so this is not as in depth as the book explains it, and also I don’t want to post their content.
Last but not least they go over how to handle a bad message coming in from a client. Now if you’re used to webservices and limited to working with just .NET that may seem needless. However keep in mind that a Java client could use your service. That’s all I got… Heroes is over and it’s bed time. I got a crapload to do at work.

