Can I provide a data member in WCF ServiceContract?

In a WCF service, is it possible to include a data item in a ServiceContract definition? To do something like this:

namespace My.Service.Contracts
{
    [ServiceContract]
    public interface IMyService
    {
        [OperationContract]
        ResultObject[] Search(SearchParams searchParams);

        [DataMember]
        MyCustomClass MyDataMember { get; }
    }
}

Is it possible to expose a MyDataMemberServiceContract from the inside? The scenario will look like this: The next class that implements the service contract has data about the members that I would like to open using a public field / property. Something similar to this: I am trying to open a field / property in a class that implements a service contract. For example:

public class MyService : IMyService
{
    private MyCustomClass _datafield;

    ResultObject[] Search(SearchParams searchParams){
        //Do the search
    }

    MyCustomClass MyDataMember {
      get: { return _dataField; }
    }
}
+4
source share
2 answers

Can a data element be included in a ServiceContract definition?

, "" , [DataMember] , WCF .

, :

[ServiceContract]
public interface IMyService
{
    [OperationContract]
    ResultObject[] Search(SearchParams searchParams);

    [DataMember]
    MyCustomClass MyDataMember { get; }
}

... , - , MyDataMember:

enter image description here

: .

enter image description here

, [DataMember]. [DataMember] , [DataContract] .

MSDN :

, , . , . ( XML) . - Golly, ...

WCF ( API , RPC ). SOAP- ( REST). , [DataMember], , . [MessageContract], .

, "" WCF, .

, WCF, . :

  • MSDN, "
+5

DataMember.

msdn.

[AttributeUsageAttribute(AttributeTargets.Property|AttributeTargets.Field, Inherited = false,AllowMultiple = false)]
public sealed class DataMemberAttribute : Attribute

, DataMember, .

.

+1

Source: https://habr.com/ru/post/1628116/


All Articles