开发者

WCF - How to use IDataSurrogate to exclude the data member depends on client requirement

开发者 https://www.devze.com 2023-02-20 18:35 出处:网络
Consider I have a DataContract with 6 properties. one client needs first 3 properties and second client needs last 3 properties of the Da开发者_运维问答ta Contract. How to write the Data Contract in a

Consider I have a DataContract with 6 properties. one client needs first 3 properties and second client needs last 3 properties of the Da开发者_运维问答ta Contract. How to write the Data Contract in a service So that the Service sends the message with only Required properties?


The correct way to do this is creating separate service for each client. Each service will expose operation using its own data contract with only required properties. Both services will be just wrapper around your core logic working with whole data object. If the reason for sending only subset of properties is data security then creating two services is the only valid option.

If we consider this more detaily the problem here is service description. If you expose metadata / WSDL on your service it will always contain the whole data contract because you can't change it dynamically. If a client creates proxy from these metadata it will also receive whole contract.

You can avoid sending some properties in SOAP message if you configure your contract to not include properties with default values and do not set them in your service but I don't think it is a good solution.

0

精彩评论

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

关注公众号