Saturday, April 9, 2011

Problem uploading large files from a client to WCF service

Impact: ProtocolException is thrown displaying message "The remote server returned an unexpected response: (400) Bad Request".

Solution: If you have just started working with WCF applications and are trying to upload small files then you might get rid of this exception, but if you are trying to upload larges files then you might have to face this exception. The solution to this problem is very simple, all you have to do is to follow the steps mentioned below.
  1. Open you WCF application's Web.config or App.config file.
  2. Find a node called <system.serviceModel>.
  3. Inside the <system.serviceModel> nodes create a node <bindings>.
  4. Then create a node matching the binding you are using. For example <basicHttpBinding></basicHttpBinding> for basicHttpBinding.
  5. In the last copy and paste the following code: <binding name="basicBinding" maxBufferPoolSize="104857600" maxReceivedMessageSize="5242880">

Note: Change the binding name according to the bindingConfiguration attribute of you endpoint and also change the size(in bytes) as per you requirement.

Example:

<system.serviceModel>
    <bindings>
      <wsDualHttpBinding>
        <binding name="DualBinding" maxBufferPoolSize="104857600" maxReceivedMessageSize="5242880">
        </binding>
      </wsDualHttpBinding>
    </bindings>

</system.serviceModel>

No comments:

Post a Comment