Thursday, February 10, 2011

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 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.

  • 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.

  • 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.

    From marc_s

0 comments:

Post a Comment