Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Do WCF Services Expose Properties?

Tags:

c#

wcf

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

like image 639
pistacchio Avatar asked May 05 '09 10:05

pistacchio


People also ask

What is a WCF service?

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.

How many endpoints can a WCF Service have?

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.

Which of the following are WCF service endpoint?

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.


2 Answers

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();
like image 142
Steve Dignan Avatar answered Sep 22 '22 11:09

Steve Dignan


You can't. That's not how it works. Methods only.

like image 26
John Saunders Avatar answered Sep 21 '22 11:09

John Saunders