Search code examples
wcfwcf-binding

Transferring big amount of data (more than 64kb) through the WCF service


I need to pass more than 64kb of data through the WCF service. To do that I've configured server side (that hosts WCF service) in the following way:

<services>
  <service name="MyService" behaviorConfiguration="MyServiceBehavior" >
    <endpoint address="" binding="customBinding" contract="MyContract"
      bindingName="testBinding" bindingConfiguration="testBinding" />
    <endpoint address="mex" binding="customBinding" contract="IMetadataExchange"
      bindingName="testBinding" bindingConfiguration="testBinding" />
  </service>
</services>

<bindings>
  <customBinding>
    <binding name="testBinding" >
      <textMessageEncoding>
        <readerQuotas maxDepth="2147483647"
          maxStringContentLength="2147483647"
          maxArrayLength="2147483647"
          maxBytesPerRead="2147483647"
          maxNameTableCharCount="2147483647" />
      </textMessageEncoding>
      <httpTransport transferMode="Buffered"
        maxReceivedMessageSize="2147483647"
        maxBufferSize="2147483647"/>
    </binding>
  </customBinding>
</bindings>

And client side (that consumes service):

<client>
  <endpoint address="http://localhost:82/MyService.svc"
    binding="customBinding" bindingConfiguration="testBinding"
    contract="MyContract"
    name="MyName" />
</client>

<bindings>
  <customBinding>
    <binding name="testBinding" >
      <textMessageEncoding>
        <readerQuotas maxDepth="2147483647"
          maxStringContentLength="2147483647"
          maxArrayLength="2147483647"
          maxBytesPerRead="2147483647"
          maxNameTableCharCount="2147483647" />
      </textMessageEncoding>
      <httpTransport transferMode="Buffered"
        maxReceivedMessageSize="2147483647"
        maxBufferSize="2147483647"/>
    </binding>
  </customBinding>
</bindings>

When I called required method I've received the following error:

Content Type application/soap+xml; charset=utf-8 was not supported by service http://localhost:82/MyService.svc. The client and service bindings may be mismatched.

Please advice, what is mismatch in my bindings?

Thanks.


Solution

  • Seems like your doing a few steps too many - too complicated. Why don't you just use a binding configuration based on an existing binding?? Something like this:

    <bindings>
      <basicHttpBinding>
        <binding name="largeBinding"
              maxBufferSize="2147483647" maxReceivedMessageSize="2147483647">
          <readerQuotas
              maxArrayLength="2147483647" maxBytesPerRead="2147483647"
              maxNameTableCharCount="2147483647" maxStringContentLength="2147483647" />
        </binding>
      </basicHttpBinding>
    </bindings>
    <services>
      <service name="MyService" behaviorConfiguration="MyServiceBehavior" >
        <endpoint 
            address="" 
            binding="basicHttpBinding" 
            bindingConfiguration="largeBinding"
            contract="MyContract" />
        <endpoint 
            address="mex" 
            binding="mexHttpBinding" 
            contract="IMetadataExchange" />
      </service>
    </services>
    

    Define the exact same binding configuration on the client side and use it there, too.

    Also, your MEX endpoint for metadata exchange should NEVER have any special setup - just use the default mexHttpBinding and don't configure any binding configuration for that.