AvocadoSoftware.com

Software For Hardcore Developers
Welcome to AvocadoSoftware.com Sign in | Join | Help
in Search

Derick Baileys old blog archives - go to derickbailey.com for new contents

WCF: Using properties on a ServiceContract interface

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

Published Wednesday, October 24, 2007 11:35 AM by dredge
Filed Under: ,
New Comments to this post are disabled

This Blog

Post Calendar

<October 2007>
SuMoTuWeThFrSa
30123456
78910111213
14151617181920
21222324252627
28293031123
45678910

Advertisement

News

this is my old blog archives - go to http://derickbailey.com for updates

Syndication

Advertisement

Powered by Community Server, by Telligent Systems