WCF

WCF

WCF Exceptions and Fault Contracts

I ran across an issue recently trying to get a custom exception across a WCF boundary. The trouble is, WCF does not like to tell you what the problem was, and for good reason. I was thinking about exceptions the wrong way. In reality we do not want to pass exceptions across a WCF service boundary, instead we want to pass a Fault back to the caller. An exception is a CLR concept, it does not make sense to expose this outside of the CLR, despite the fact that an exception contains potentially dangerous information (like the stack trace) which...

WCF: Custom Collections with Extra Payload

I came across a pretty annoying problem to solve in WCF today. Suppose you have a custom collection of items you wish to use in a WCF contract but it also has extra properties that you have added, for example change tracking.     [Serializable]     public class DtoCollection<T> : List<T>     {         private List<T> addedItems;         private List<T> removedItems;     }   It will serialize the collection fine but your added properties and fields will not appear. The [CollectionDataContract] attribute will not help you. If you look at this really great post from Sowmy Srinivasan's blog you can see the order of preference for WCF serialization markup....