Return custom WCF types

I am new to WCF, trying to accomplish a relatively simple task. I am trying to return a list of objects read from a database, but cannot overcome some really annoying exceptions. The question is very simple? What is wrong with the image?

[ServiceContract]
public interface IDBService
{        
    [OperationContract]
    string Ping(string name);

    [OperationContract]
    InitBDResult InitBD();
}

public InitBDResult InitBD()
        {
            _dc = new CentralDC();
            InitBDResult result = new InitBDResult();
            result.ord = _dc.Orders.First();
            return result;
        }


[DataContract]
    public class InitBDResult
    {
        //[DataMember]
        //public List<Order> Orders { get; set; }

        [DataMember]
        public Order ord { get; set; }
    }
+3
source share
2 answers

Based on what you posted:

public InitBDResult InitBD()
{
    _dc = new CentralDC();
    InitBDResult result = new InitBDResult();
    result.ord = _dc.Orders.First();
    return result;
}

IDBServiceIs this method contained in a class that implements the interface ? This is not entirely clear from your post ....

[DataContract]
public class InitBDResult
{
        //[DataMember]
        //public List<Order> Orders { get; set; }

        [DataMember]
        public Order ord { get; set; }
}

Is the Order class also labeled [DataContract]and any properties that need to be serialized with attributes[DataMember]

WCF , ( ), [DataContract] , , [DataMember].

[Serializable] WCF . WCF MSDN - !

WCF, , . :

 <behaviors>
    <serviceBehaviors>
      <behavior name="debugging">
        <serviceDebug includeExceptionDetailInFaults="true"/>
      </behavior>
    </serviceBehaviors>
  </behaviors>

:

<service name="...." behaviorConfiguration="debugging">

, "- ".

+3

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


All Articles