简体   繁体   中英

Using a WCF Service with Complex Data Types

I'm trying to pass a DTO with one navidation property IEnumerable<> inside of it, when I pass an object without child lists it works well, but, when I'm passing objects with childs and grandchilds the WCF services does not respond and gives me no error. I have to make something to work with this type of object specificly?

Here's my data contract

    [ServiceContract]
        public interface IProdutoService
        {
            [OperationContract]
            CategoriaResponse GetCategoria(CategoriaRequest request);

            [OperationContract]
            ProdutoResponse GetProduto(ProdutoRequest request);

            [OperationContract]
            CategoriaResponse ManageCategoria(CategoriaRequest request);

            [OperationContract]
            ProdutoResponse ManageProduto(ProdutoRequest request);
        }


//and then my DTO Class

 public class ProdutoDto
    {
        #region Primitive Properties
        [DataMember]
        public Int32 Codigo { get; set; }

        [DataMember]
        public Int32 CodigoCategoria { get; set; }

        [DataMember]
        public String Descricao { get; set; }

        [DataMember]
        public Decimal? Preco { get; set; }
        #endregion


        #region Navigation Properties
        [DataMember]
        public CategoriaDto Categoria { get; set; }

        [DataMember]
        public VendaDto[] Vendas { get; set; }
        #endregion
    }

// And my service configuration looks like this:

<services>
  <service behaviorConfiguration="behaviorAction" name="Uniarchitecture.ProdutoService.ServiceImplementations.ProdutoService">
    <endpoint binding="wsHttpBinding" bindingConfiguration="bindingAction" contract="Uniarchitecture.ProdutoService.ServiceContracts.IProdutoService">
      <identity>
        <dns value="localhost"/>
      </identity>
    </endpoint>
    <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
  </service>
</services>

<behaviors>
  <serviceBehaviors>
    <behavior name="behaviorAction">
      <serviceMetadata httpGetEnabled="true" />
      <serviceDebug includeExceptionDetailInFaults="true"/>
    </behavior>
  </serviceBehaviors>
</behaviors>


<bindings>
  <wsHttpBinding>
    <binding name="bindingAction" transactionFlow="false" receiveTimeout="00:30:00" >
      <reliableSession enabled="true"/>
    </binding>
  </wsHttpBinding>
</bindings>

It is probably that your child objects are not marked as Serializable.

It also looks as if you are Missing the DataContract attribute.

From the comments below it looks like you have some objects that are not serializable. Go through all the objects that you use and mark them all with th serializable or the data contract attribute.

那么,您必须使用合同意识循环引用。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM