WCF Error: 413 Request Entity Too Large

 

When we use WCF to transfer data, if the default configuration is enabled, the amount of data transferred is too large, and this error often occurs.

WCF includes a server and a client, so this error may occur when the server returns data to the client, or the client transmits data to the server.

1. The server returns data to the client and reports an error

In the client configuration file, the main thing is to configure maxReceivedMessageSize

copy code
<system.serviceModel>
    <bindings>
      <basicHttpBinding>
        <binding name="ServiceProxyBinding" closeTimeout="00:10:00" receiveTimeout="00:10:00"
          sendTimeout="00:10:00" maxBufferSize="2147483647" maxReceivedMessageSize="2147483647">
          <readerQuotas maxStringContentLength="134217728" />
        </binding>
      </basicHttpBinding>
    </bindings>
    <client>
      <endpoint address="http://localhost:5239/AHMTService/PartService.svc"
        binding="basicHttpBinding" bindingConfiguration="ServiceProxyBinding"
        contract="UniCloud.ServiceContracts.IPartService" name="IPartService" />
    </client>
  </system.serviceModel>
copy code

2 The client transmits data to the server and reports an error

 Modify the server web.config, mainly to configure maxReceivedMessageSize

copy code
<system.serviceModel>
    <services>
      <!--DecodeService server configuration increases the size of the received file-->
      <service name="UniCloud.Services.DecodeService" behaviorConfiguration="MyServiceBehaviour" >
        <endpoint address="" binding="basicHttpBinding" bindingConfiguration="MyServiceBinding" contract="UniCloud.ServiceContracts.IDecodeService">
        </endpoint>
        <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
        <host>
          <baseAddresses>
            <add baseAddress="http://localhost:5239/AHMTService"/>
          </baseAddresses>
        </host>
      </service>
    </services>
    <bindings>
      <basicHttpBinding>
        <binding name="MyServiceBinding"  closeTimeout="00:10:00" receiveTimeout="00:20:00" sendTimeout="00:20:00"
maxBufferSize="2147483647" maxReceivedMessageSize="2147483647">
          <security mode="None"></security>
        </binding>
      </basicHttpBinding>
    </bindings>
    <behaviors>
      <serviceBehaviors>
        <behavior name="MyServiceBehaviour">
          <!-- To avoid leaking metadata information, please set the following values ​​to false before deploying -->
          <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true" />
          <!-- To receive failure exception details for debugging, set the following value to true. Set to false before deployment to avoid leaking exception information -->
          <serviceDebug includeExceptionDetailInFaults="true" />
          <dataContractSerializer maxItemsInObjectGraph="2147483647"/>
        </behavior>
      </serviceBehaviors>
    </behaviors>
    <protocolMapping>
      <add binding="basicHttpsBinding" scheme="https" />
    </protocolMapping>
    <serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
  </system.serviceModel>
copy code

 

In fact, to modify all services, whether it is the server or the client, it is OK to add a default configuration without a name to the Binding.

<binding   closeTimeout="00:10:00" receiveTimeout="00:20:00" sendTimeout="00:20:00"
maxBufferSize="2147483647" maxReceivedMessageSize="2147483647">

When we use WCF to transfer data, if the default configuration is enabled, the amount of data transferred is too large, and this error often occurs.

WCF includes a server and a client, so this error may occur when the server returns data to the client, or the client transmits data to the server.

1. The server returns data to the client and reports an error

In the client configuration file, the main thing is to configure maxReceivedMessageSize

copy code
<system.serviceModel>
    <bindings>
      <basicHttpBinding>
        <binding name="ServiceProxyBinding" closeTimeout="00:10:00" receiveTimeout="00:10:00"
          sendTimeout="00:10:00" maxBufferSize="2147483647" maxReceivedMessageSize="2147483647">
          <readerQuotas maxStringContentLength="134217728" />
        </binding>
      </basicHttpBinding>
    </bindings>
    <client>
      <endpoint address="http://localhost:5239/AHMTService/PartService.svc"
        binding="basicHttpBinding" bindingConfiguration="ServiceProxyBinding"
        contract="UniCloud.ServiceContracts.IPartService" name="IPartService" />
    </client>
  </system.serviceModel>
copy code

2 The client transmits data to the server and reports an error

 Modify the server web.config, mainly to configure maxReceivedMessageSize

copy code
<system.serviceModel>
    <services>
      <!--DecodeService server configuration increases the size of the received file-->
      <service name="UniCloud.Services.DecodeService" behaviorConfiguration="MyServiceBehaviour" >
        <endpoint address="" binding="basicHttpBinding" bindingConfiguration="MyServiceBinding" contract="UniCloud.ServiceContracts.IDecodeService">
        </endpoint>
        <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
        <host>
          <baseAddresses>
            <add baseAddress="http://localhost:5239/AHMTService"/>
          </baseAddresses>
        </host>
      </service>
    </services>
    <bindings>
      <basicHttpBinding>
        <binding name="MyServiceBinding"  closeTimeout="00:10:00" receiveTimeout="00:20:00" sendTimeout="00:20:00"
maxBufferSize="2147483647" maxReceivedMessageSize="2147483647">
          <security mode="None"></security>
        </binding>
      </basicHttpBinding>
    </bindings>
    <behaviors>
      <serviceBehaviors>
        <behavior name="MyServiceBehaviour">
          <!-- To avoid leaking metadata information, please set the following values ​​to false before deploying -->
          <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true" />
          <!-- To receive failure exception details for debugging, set the following value to true. Set to false before deployment to avoid leaking exception information -->
          <serviceDebug includeExceptionDetailInFaults="true" />
          <dataContractSerializer maxItemsInObjectGraph="2147483647"/>
        </behavior>
      </serviceBehaviors>
    </behaviors>
    <protocolMapping>
      <add binding="basicHttpsBinding" scheme="https" />
    </protocolMapping>
    <serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
  </system.serviceModel>
copy code

 

In fact, to modify all services, whether it is the server or the client, it is OK to add a default configuration without a name to the Binding.

<binding   closeTimeout="00:10:00" receiveTimeout="00:20:00" sendTimeout="00:20:00"
maxBufferSize="2147483647" maxReceivedMessageSize="2147483647">

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324791208&siteId=291194637