Do WCF Services Expose Properties?

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


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

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:

public interface IService1
    string Name


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();

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.

You can expose properties but u will have to use [DataContract] attribute and can declare property as [DataMember] attribute for properties.

PLEASE PLEASE don't expose Properties as a web method.. This will not work in HTTPS. I had BIG time identifying and fixing this issue. The best way is to write a concrete method to return in WCF.

Need Your Help

How to put GridView inside ScrollView

android gridview scrollview

I have to design layout such that whole layout should scroll and inside layout I have to display related content in Grid form so I decided to use GridView.But problem is that I’m unable to use Grid...

Get rid of Vim's highlight after searching text


In VIM, after finding text with "/" command, that text remains highlighted.