开发者

WCF internal property

I have a class with a Property :

[DataMember]
public bool MyProp { get; internal set;}

I notice that when the proxy is generated. The property is 开发者_StackOverflow社区still settable even though I have marked it internal ( I thought that it won't be generated at all ).

Is there a way to achieve what I'm trying? I'd like to be able to set the property from the service side. But not allow the client side to be able to set the property.


A [DataMember] on a WCF contract is just a data field on a data contract - an XML schema. The .NET setter and getter visibility modifier are irrelevant when dealing with WCF messages, really.

If your field has a [DataMember] attribute, it will be part of the XML schema of your data contract - and the client cannot know that it has an "internal" setter on the server side - it's just part of the XSD data contract.

.NET and WCF are two very distinct and separate worlds - when your client calls a WCF service, it's a SOAP-based message passing only - there's no .NET based object interaction! You're not reaching out from your client to the server to call a method on an object on the server side - in which case maybe a .NET visibility specifier would come into play. Your client creates a messages and sends that to the server, which then reassembles the (server-side) object from that message - heck, there's even a SMTP (e-mail!) based transport for WCF!

The only thing the two sides share are contracts - service/operation contracts for your service methods, and XML schema based data contracts for your data being passed around. There' no concept of .NET based visibility specifications in XML schema.


As with Service Contracts, access modifiers on DataContracts/DataMembers do not play any role and are in essence meaningless :(


Without a get and set, you cannot serialize and deserialize over a WCF hop.

You could implement what you are trying to do in the logic of your service.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜