views:

101

answers:

3

I'm having trouble using properties in a WCF service. I can define a property in the interface as:

[ServiceContract(Namespace = "http://some-url.com/")]
interface ISomeInterface
{
  [OperationContract]
  int SomeMethod(string someArg);

  int SomeProperty
  {
    [OperationContract]
    get;
  }
}

But when consumed by a client, the property's underlying method get_SomeProperty() is exposed, rather than as a getter property. Is there a way to tell the client to see it as a property? (Or must I just abandon the use of properties in service contracts?)

+4  A: 

No SOAP web services anywhere in the world supports properties. There is no way to describe a property in a WSDL. Web Services are about operations (methods) only.

John Saunders
+3  A: 

In WCF, all you can do is send messages between client and server.

The client never has direct rpc-style access to the server object - therefore, you cannot surface properties or anything like that.

All you can do is serialize messages and send them to a method with the [OperationContract] on them. This cannot be applied to setter methods of properties, I believe.

Marc

marc_s
+1  A: 

A Web Service doesn't expose properties. It only exposes its methods that can be called by the clients (a Web Service is stateless...so having properties really doesn't makes sense because they'd always be the initial value).

Justin Niessner