Recently, I have been asked around some of the scenarios where in client is invoking service with extra properties, which is not part of Data Contract actually. In this kind of scenario, basically client loses the data and sometime even service blows up at runtime. Best way to handle the same is via Version Tolerance. Now, let us see the same in detail.
Version Tolerance is one of the cool features provided by the Data-Contract Serializer. This is one of the things, which is not provided by XML Serializer. One point to note here that Data-Contract is version tolerant up to a certain point. Therefore, there could be a situation that one contract is missing a property, means on the server, one property is missing. And client is running with an extra property. Here, client will make a call by filling up three properties and goes to the service and when service receives this call; it does not break. It simply throws away the extra one. Therefore, this kind of fix you will get by default from Data-Contract Serializer. Similarly, when service is returning the response to the client then in that case it will return with two properties filled with data and the extra one will be returned blank if its string type or zero if its integer type means default value based on the type. Now, due to this kind of situation, client will lose the data.
To fix this kind of problem, we use IExtensibleDataObject Interface. Here, all we need to do is to implement this interface in the Data-Contract. This also means WCF will use this an additional container for holding any extra values coming in. So, all we need is the below shown implementation. This will handle all the missing values.
This kind of all scenarios are explained in http://bit.ly/pragmaticWCF-kindle
I hope you would have liked this discussion. Will delve further in coming posts. Till then, stay tuned and Happy Coding.
2,140 total views, 1 views today