开发者

WCF Service - Different datacontracts for SOAP + XML and JSON endpoints

I have a .NET 3.5 WCF Service which is currently a SOAP + XML service. There is now a need to expose this same service to some clients who need the responses in JSON format.

While going over other SO questions about it and their answers, i believe that this in itself should be possible by having 2 different endpoints as explained here

However, i have a slightly bigger complication. The DataContracts to be exposed via the JSON service need to be altered i.e not all the properties that are currently exposed by the SOAP service are needed. The JSON object needs to expose only a subset of the properties.

Is there is any way to have the DataContractJsonSerializer serializer omit certain fields which are decorated with the DataContract attribute? This cl开发者_Python百科ass is sealed so inheriting it is not an option. Do i need to write my own serializer here and if so, how would i go about instructing WCF to use my custom serializer?


Once you are using DataContractSerializer and DataContractJsonSerializer on the same type they will always serialize same properties because these classes use same rules for serializtion. The easiest (and correct) way is simply define new service contract for second enpoint (or whole new service) and expose operations with new data contracts.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜