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
Windows Communication Foundation (WCF) is a framework for building service-oriented applications. Using WCF, you can send data as asynchronous messages from one service endpoint to another. A service endpoint can be part of a continuously available service hosted by IIS, or it can be a service hosted in an application.
The service configuration has been modified to define two endpoints that support the ICalculator contract, but each at a different address using a different binding.
The endpoint is the fusion of the address, contract, and binding (see Figure 1-8). Every endpoint must have all three elements, and the host exposes the endpoint.
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();
You can't. That's not how it works. Methods only.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With