Tuesday, March 30, 2010

Property Handling in WCF

In this article I am talking about how you can define OperationContract for your properties of Service Contract.

As you know you can't put [OperationContract] attribute on your Properties it will give you an compile time error because this attribute is only valid for method declaration.

In this case you can define this attribute on you get and set of property and these get and set will treat as normal method so for example I am define one property called CustomerId I have to define like this.

int CustomerId
{

[OperationContract]
get;
[OperationContract]
set;
}
After doing this you will get set_CustomerId and get_CustomerId as normal method in your WCF proxy class.

No comments: