Took me a bit to figure this out, so I thought I would share with the world. If you want to have a property on a [ServiceContract] interface, your property has to specify [OperationContract] for the get and set (whichever you are providing).
For example, let's say you want to use this interface:
public interface IDoSomething
{
public void DoSomething();
public int MyValue { get; }
public int YourValue { get; set; }
}
The obvious part for me, was adding the [ServiceContract] to the interface and the [OperationContract] to the DoSomething method. What is not obvious, is adding the [OperationContract] to the get; and set; definitions, which allows WCF to execute those operations. The end result looks like this:
[ServiceContract]
public interface IDoSomething
{
[OperationContract]
public void DoSomething();
public int MyValue
{
[OperationContract] get;
}
public int YourValue
{
[OperationContract] get;
[OperationContract] set;
}
}
I wasn't even aware that you could specify an attribute on the get; and set; until I started trying to figure this out... that has some interesting implications, actually, and also re-confirms what I already knew about the MSIL being generated for a property get / set - it's actually a method call behind the scenes. C# (and many other .NET languages) simply provide a language construct to simplify and standardize the use of properties. Under the hood, though, the MSIL is more like Java in that both Java and MSIL do not support properties directly, but rather they standardize on naming conventions (although I think MSIL actually includes the "get" and "set" keywords as well).