is it possible to include a data member inside a ServiceContract definition?
Although the compiler will quite happily let you "add" a property decorated with [DataMember]
to the service interface, any WCF client will not see the property.
So if your service interface was defined as:
[ServiceContract]
public interface IMyService
{
[OperationContract]
ResultObject[] Search(SearchParams searchParams);
[DataMember]
MyCustomClass MyDataMember { get; }
}
...and say you generated the client proxy by Add Service Reference, you would see no mention of MyDataMember
:

Note, at the point of adding the service reference you won't see any properties either.

It does not make sense to add properties to a service interface, nor does it make sense to add [DataMember]
. You add [DataMember]
to a class decorated with [DataContract]
and referenced in your service's interface.
MSDN has this to say on data contracts:
A data contract is a formal agreement between a service and a client that abstractly describes the data to be exchanged. That is, to communicate, the client and the service do not have to share the same types, only the same data contracts. A data contract precisely defines, for each parameter or return type, what data is serialized (turned into XML) to be exchanged. - Golly, tell me more...
WCF essentially is all about invoking methods (actually it is more about creating a unified communications API giving you RPC as the free set of steak knives). Methods are generally invoked by sending SOAP messages to the service (though it could be REST too). Messages have properties which are decorated with [DataMember]
to indicate that the property should be serialised and included in the message stream. There's also [MessageContract]
but we won't go there.
Anyway, one does not access "a property" on a WCF service, instead you invoke a method.
Tell me more
To learn more about the epic-ness that is WCF, why not check out the link below. There's even a rather nice example at the bottom: