views:

379

answers:

2

I have a WCF Service operation which takes an object as a parameter. This object has a byte[] property among others. A Client program calls this service operation using a svcutil generated proxy.

when client program populates the object's bype[] propery with size more than 50Kb it throws following error. (while an image size smaller than 50kb assigned to the byte[], it works).

The error which I am getting is:

System.ServiceModel.ProtocolException was unhandled Message="The remote server returned an unexpected response: (400) Bad Request."

This is my Server side Config:

<system.serviceModel>
<diagnostics>
   <messageLogging logMalformedMessages="false" logMessagesAtServiceLevel="false"
    logMessagesAtTransportLevel="false" />
</diagnostics>
<services>
  <service behaviorConfiguration="ProjectABC.ABCServiceBehavior"
    name="ProjecXAPI.ContentService">
     <endpoint address="" binding="basicHttpBinding" bindingConfiguration="testContentBinding"
      bindingName="testContentBinding" contract="ProjectABC.IABCtService" />
     <endpoint address="mex" binding="mexHttpBinding" bindingConfiguration="higherMessageSize_MEX"
      contract="IMetadataExchange" />
  </service>
</services>
<behaviors>
 <serviceBehaviors>
  <behavior name="ProjectABC.ABCServiceBehavior">
   <serviceMetadata httpGetEnabled="true"/>
            <dataContractSerializer maxItemsInObjectGraph="2147483647"/>
   <serviceDebug includeExceptionDetailInFaults="true"/>
  </behavior>
 </serviceBehaviors>
</behaviors>
<bindings>
  <basicHttpBinding>
    <binding name="testContentBinding" messageEncoding="Mtom" transferMode="Buffered">
      <readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647" maxArrayLength="2147483647"
                    maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
      <security mode="None"></security>
    </binding>
  </basicHttpBinding>
  <mexHttpBinding>
    <binding name="higherMessageSize_MEX"/>
  </mexHttpBinding>
</bindings>
</system.serviceModel>

This is my Client side Config:

<system.serviceModel>
<bindings>
  <basicHttpBinding>
    <binding name="testContentBinding_IContentService" closeTimeout="01:01:00"
        openTimeout="01:01:00" receiveTimeout="01:10:00" sendTimeout="01:01:00"
        allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
        maxBufferSize="2147483647" maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647"
        messageEncoding="Mtom" textEncoding="utf-8" transferMode="Buffered"
        useDefaultWebProxy="true">
      <readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647" maxArrayLength="2147483647"
          maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
      <security mode="None">
        <transport clientCredentialType="None" proxyCredentialType="None"
            realm="" />
        <message clientCredentialType="UserName" algorithmSuite="Default" />
      </security>
    </binding>
  </basicHttpBinding>
</bindings>

<client>
  <endpoint address="http://localhost:2361/Content/ContentService.svc"
            binding="basicHttpBinding" bindingConfiguration="testContentBinding_IContentService"
            contract="IContentService" name="testContentBinding_IContentService" />
</client>
</system.serviceModel>
+3  A: 

Ok, I am answering my own question here -

Just found out that there is a setting on in server side config "maxReceivedMessageSize". Once you set this to the max size you want server to accept, you are ready to go.

Thanks & Regards, Ajay

Ajay
A: 

Hello, Here is the solution for the problem. The server side config needs some settings to be done as given below:

<basicHttpBinding>
<binding name="ExampleBinding" transferMode="Buffered" messageEncoding="Mtom" maxReceivedMessageSize="104857600" maxBufferPoolSize="524288">
  <readerQuotas maxDepth="32" maxStringContentLength="104857600" maxArrayLength="104857600"
   maxBytesPerRead="4096" maxNameTableCharCount="104857600" />
  <security mode="None">
 <transport clientCredentialType="None" proxyCredentialType="None" realm=""/>
 <message clientCredentialType="UserName" algorithmSuite="Default"/>
  </security>
</binding>
</basicHttpBinding>
Swapnil