I cannot change maximum size quota for incoming message, WCF Service

212 Views Asked by At
**Web Config:**
<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <appSettings>
    <add key="aspnet:UseTaskFriendlySynchronizationContext" value="true" />
  </appSettings>
  <system.web>
    <compilation debug="true" targetFramework="4.6.1" />
    <httpRuntime targetFramework="4.6.1" />
  </system.web>
  <system.serviceModel>
    <serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
    <behaviors>
      <serviceBehaviors>
        <behavior>
          <!-- To avoid disclosing metadata information, set the values below to false before deployment -->
          <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true" />
          <!-- To receive exception details in faults for debugging purposes, set the value below to true.  Set to false before deployment to avoid disclosing exception information -->
          <serviceDebug includeExceptionDetailInFaults="false" />
        </behavior>
      </serviceBehaviors>
    </behaviors>
    <protocolMapping>
        <add binding="basicHttpsBinding" scheme="https" />
    </protocolMapping>
    <!--Add refernce to any new service that is to be added
    <serviceHostingEnvironment aspNetCompatibilityEnabled="true"
      multipleSiteBindingsEnabled="true">
      <serviceActivations>
        <add relativeAddress="EmployeeService.svc" service="PeopleInbox.ServiceLibrary.EmployeeService" />
        <add relativeAddress="LookupService.svc" service="PeopleInbox.ServiceLibrary.LookupService" />
        <add relativeAddress="SecurityService.svc" service="PeopleInbox.ServiceLibrary.SecurityService" />
        <add relativeAddress="EmployerService.svc" service="PeopleInbox.ServiceLibrary.EmployerService" />
      </serviceActivations>
    </serviceHostingEnvironment>-->
    <services>
      <service name="PeopleInbox.ServiceLibrary.EmployeeService">
        <endpoint address="" binding="basicHttpBinding" contract="PeopleInbox.ServiceLibrary.IEmployeeService">
          <identity>
            <dns value="localhost" />
          </identity>
        </endpoint>
        <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
        <host>
          <baseAddresses>
            <add baseAddress="http://localhost/PeopleInbox.ServiceLibrary/EmployeeService/" />
          </baseAddresses>
        </host>
      </service>

      <service name="PeopleInbox.ServiceLibrary.AdminService">
        <endpoint address="" binding="basicHttpBinding" contract="PeopleInbox.ServiceLibrary.IAdminService">
          <identity>
            <dns value="localhost" />
          </identity>
        </endpoint>
        <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
        <host>
          <baseAddresses>
            <add baseAddress="http://localhost/PeopleInbox.ServiceLibrary/AdminService/" />
          </baseAddresses>
        </host>
      </service>

      <service name="PeopleInbox.ServiceLibrary.LookupService">
        <endpoint address="" binding="basicHttpBinding" contract="PeopleInbox.ServiceLibrary.ILookupService">
          <identity>
            <dns value="localhost" />
          </identity>
        </endpoint>
        <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
        <host>
          <baseAddresses>
            <add baseAddress="http://localhost/PeopleInbox.ServiceLibrary/LookupService/" />
          </baseAddresses>
        </host>
      </service>
      <service name="PeopleInbox.ServiceLibrary.SecurityService">
        <endpoint address="" binding="basicHttpBinding" contract="PeopleInbox.ServiceLibrary.ISecurityService">
          <identity>
            <dns value="localhost" />
          </identity>
        </endpoint>
        <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
        <host>
          <baseAddresses>
            <add baseAddress="http://localhost/PeopleInbox.ServiceLibrary/SecurityService/" />
          </baseAddresses>
        </host>
      </service>
    </services>
  </system.serviceModel>
  <system.webServer>
    <modules runAllManagedModulesForAllRequests="true" />
    <!--
        To browse web app root directory during debugging, set the value below to true.
        Set to false before deployment to avoid disclosing web app folder information.
      -->
    <directoryBrowse enabled="true" />
  </system.webServer>

  <runtime>

    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">

      <dependentAssembly>

        <assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" culture="neutral" />

        <bindingRedirect oldVersion="0.0.0.0-5.2.4.0" newVersion="5.2.4.0" />

      </dependentAssembly>

    </assemblyBinding>

  </runtime>
</configuration>

Error The maximum message size quota for incoming messages (65536) has been exceeded. To increase the quota, use the MaxReceivedMessageSize property on the appropriate binding element.

Please tell where to set maxReceivedMessageSize. I cannot able to create binding and don't know how to use the. I check lot of tutorial but cannot find the correct answer that make code running. Thanks

1

There are 1 best solutions below

1
Tim On

You need to create a binding configuration and assign it to the bindingConfiguration attribute on the service(s).

To create a binding, you add a section in the <system.serviceModel> section of the config file, for example:

<bindings>
  <basicHttpBinding>
    <binding name="MyHttpBinding" 
             maxReceivedMessageSize="2147483647" />
  </basicHttpBinding>
</bindings>

Then in your service endpoints you assign the above binding via the bindingConfiguration attribue on the <endpoint> element. For example:

<endpoint address="" binding="basicHttpBinding" 
          bindingConfiguration="MyHttpBinding"
          contract="PeopleInbox.ServiceLibrary.IAdminService">

This will result in the defined endpoint using the binding you defined (which has the maxReceivedMessageSize value set to the maximum value for the attribute (Int32.MaxValue), instead of the default value of 65536 for basicHttpBinding.