Posts

Showing posts with the label WCF

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.

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...

Changing the type of a returned object in WCF

[ Download Full Solution ] Every once and a while the returned object type from a service is too simple/generic, and a more rich, or specialized object would be a better fit. This is typically easy to achieve by instructing a new type that's comparable with the same service contract to be the resulting type. What about if one XML representation could best be described as multiple classes though? What this article tries to demonstrate is how to closely manage the DataContractSerializer in such a way that the returned type through the WCF endpoint is the desired type, while remapping it at the level of the serializer if appropriate. What we have below is how we are going to update the DataContractSerializer to do our bidding. We are going to create a new implementation of IEndpointBehavior which will update the DataContractSerializer on the operational contracts of the assigned endpoint. <?xml version="1.0" encoding="utf-8" ?> <configuration> ...