WCF Web Service Operation Throws Exception When Transferring More Than 50 Kbytes Bytes []

I have a WCF Service operation that takes an object as a parameter. This object has the byte [] property among others. The client program invokes this operation using the proxy server generated by svcutil.

when the client program fills the bype [] object with a size of more than 50 KB, it throws the following error. (while the image size is less than 50 kbytes assigned to byte [], it works).

The error I am getting is:

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

This is my server side configuration:

<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 configuration:

<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
2

, -

, "maxReceivedMessageSize". , , , .

,

+3

. , , :

<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>
0

Source: https://habr.com/ru/post/1714404/


All Articles