Hi, In the interface required to implement a WCF service, I declare the main class with the [ServiceContract()] attribute and any exposed method with [OperationContract()].
How can i expose public properties? Thanks
Hi, In the interface required to implement a WCF service, I declare the main class with the [ServiceContract()] attribute and any exposed method with [OperationContract()].
How can i expose public properties? Thanks
Properties are an object oriented aspect of component interfaces. WCF is about services, where you have to think about and design the sequence of interactions between your components.
Object orientation does not scale well to distributed scenarios (where your code executes on multiple servers or even in multiple processes) due to the cost of roundtrips, potentially expensive state management, and versioning challenges. However, OO is still a good way of designing the internals of services, especially if they are complex.
Since the get portion of a property is a method, this will technically work but, as mentioned in previous answers/comments, this may not be advisable; just posting it here for general knowledge.
Service Contract:
[ServiceContract]
public interface IService1
{
string Name
{
[OperationContract]
get;
}
}
Service:
public class Service1 : IService1
{
public string Name
{
get { return "Steve"; }
}
}
To access from your client code:
var client = new Service1Client();
var name = client.get_Name();