Wednesday 4 August 2010

Handling custom errors in WCF

[Download Full Solution]

In WCF the preferred way to handle custom error/exception states is through creating an object that can be serialized containing the fault information, and assigning it against an OperationContractAttribute decorated method using the FaultContractAttribute. Assigning a FaultContractAttribute provides an alternate object type to pass back to the client. The default action on the client is to raise a FaultException<MyCustomFault> which allows for the returned fault to be returned in the generic type.

Wednesday 17 February 2010

Custom Proxy Generation using "RealProxy"

[Download Full Solution]

I've been looking around the top side of the WCF client proxy for a nice place to hook in contract specific caching. I was hoping to find soemthing similar to the IOperationInvoker on the server end. Unfortunately I couldn't find anything that allowed for me to fully divert the flow and avoid a service call. You have the ability to inspect the parameter listing (pre-validation), and the message (further validation or header injection) after serialization (which you can also adjust) but at no point can you just return a value within the pipeline...