Koda
Koda

Reputation: 1857

Sending a dictionary using WCF, WSBinding

I am currently trying to create a webservice in a winform application using WCF, WShttpBinding. One of the methods returns a dictionary. The client side, an RTD Server will call this method to retrieve the dictionary.

For some reason, when the dictionary gets too large( 0.6MB +), a communication exception will be thrown. I have tried increasing the size of the following parameters both on the clientside and serverside, but it still willnot work. Can someone tell me what I am doing wrong? Thanks.

binding.MaxReceivedMessageSize
binding.MaxBufferPoolSize
binding.SendTimeout 
binding.OpenTimeout
binding.ReceiveTimeout 
binding.ReaderQuotas.MaxStringContentLength 
binding.ReaderQuotas.MaxDepth 
binding.ReaderQuotas.MaxBytesPerRead

Upvotes: 0

Views: 411

Answers (1)

Otiel
Otiel

Reputation: 18743

Add a behavior configuration in your App.config files:

  • On the server:

 

<behaviors>
    <serviceBehaviors>
        <behavior name="MyServiceBehavior">
            <dataContractSerializer maxItemsInObjectGraph="2147483647"/>
        </behavior>
    </serviceBehaviors>
</behaviors>
  • On the client:

 

<behaviors>
    <endpointBehaviors>
        <behavior name="MyClientBehavior">
            <dataContractSerializer maxItemsInObjectGraph="2147483647"/>
        </behavior>
    </endpointBehaviors>
</behaviors>

Note that 2147483647 is the max value and maybe you don't need that much.


And don't forget to reference the behavior in your services and endpoints:

  • On your server (and on your client if it hosts some services):

 

<service name="SomeService" behaviorConfiguration="MyServiceBehavior">
    <endpoint binding="WShttpBinding" 
              bindingConfiguration="MyBindingConf" 
              contract="SomeContract"/>
</service>
  • On your client:

 

<endpoint binding="WShttpBinding" 
          bindingConfiguration="MyBindingConf"
          behaviorConfiguration="MyServiceBehavior" 
          contract="SomeContract" 
          name="SomeName" />

Upvotes: 3

Related Questions