views:

310

answers:

2

Hi guys, 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>
A: 

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.

Shiraz Bhaiji
I've put the data contract but then the service gives me the following error:Type 'Uniarchitecture.ProdutoService.Messages.CategoriaRequest' cannot inherit from a type that is not marked with DataContractAttribute or SerializableAttribute. Consider marking the base type 'Uniarchitecture.ProdutoService.MessageBase.RequestBase' with DataContractAttribute or SerializableAttribute, or removing them from the derived type.Looking foward to it.
Diego Correa
Yeah. You'll need to make CategoriaRequest and all the other requests/responses `DataContracts`, and their used properties `DataMembers`. This also includes CategoriaDto and VendaDto.
Dan Atkinson
Well, I figured out and fixed it, but, still, when I pass an list of products with a sales list child....it gaves me a timeout.
Diego Correa
Then it is now the amount of data that is being transfered that is causing it to timeout. You can increase the timeout in the behaviour configuration.
Shiraz Bhaiji
Added time for 10 minutes and it not worked......I'm passing a collection with about 50 objects..
Diego Correa
Could you post relevant parts of your config files server and client?
Shiraz Bhaiji
The configs are almost default, the server I've posted above, the cliente is the default config when you create a service reference for WCF...ok I'll post it.
Diego Correa
You told that I'm marking all my dtos with data contract and datamember atributes. my child objects are another DTOs with contracts and datamember marked in.
Diego Correa
A: 

Well you must use contract aware cyclic references.

Diego Correa