1

This question may already has an answers, but none of them worked for me. I'm very new to WCF and this's very first project I'm working.

Answers I've tried:

The maximum message size quota for incoming messages (65536) has been exceeded

Wcf-The maximum message size quota for incoming messages (65536) has been exceeded?

WCF Error - The maximum message size quota for incoming messages (65536) has been exceeded

I've created a project and ran successfully on local machine. When I publish it on IIS and running it under Windows Form Application, I get this 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.

This is my server (WCF) web.config:

<?xml version="1.0"?>
<configuration>
   <appSettings>
      <add key="connectionString" value="data source=localhost; initial catalog=TWO; integrated security=SSPI"/>
   </appSettings>
   <system.web>
       <compilation debug="true" targetFramework="4.0" />
       <pages validateRequest="false" />
       <httpRuntime requestValidationMode="2.0" />
   </system.web>
   <system.serviceModel>
      <services>
         <service name="Service1.IService1">
            <endpoint 
                address="" 
                binding="basicHttpBinding" 
                contract="Service1.IService1">
            </endpoint>
            <host>
               <baseAddresses>
                   <add baseAddress="http://localhost:50935/Service1.svc"/>
               </baseAddresses>
           </host>
       </service>
   </services>
   <bindings>
      <basicHttpBinding>
         <binding  
              maxBufferPoolSize="2147483647" maxBufferSize="2147483647" 
              maxReceivedMessageSize="2147483647" messageEncoding="Text">
            <readerQuotas maxDepth="2000000" 
                   maxStringContentLength="2147483647" 
                   maxArrayLength="2147483647" 
                   maxBytesPerRead="2147483647" 
                   maxNameTableCharCount="2147483647" />
         </binding>
      </basicHttpBinding>
   </bindings>
   <behaviors>
       <serviceBehaviors>
           <behavior>
              <serviceMetadata httpGetEnabled="true"/>
              <serviceDebug includeExceptionDetailInFaults="false"/>
           </behavior>
       </serviceBehaviors>
       <endpointBehaviors>
           <behavior name="behaviorGPLineItemsService">
               <dataContractSerializer maxItemsInObjectGraph="2147483647"/>
           </behavior>
       </endpointBehaviors>
    </behaviors>
    <serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
</system.serviceModel>
<system.webServer>
  <modules runAllManagedModulesForAllRequests="true"/>
</system.webServer>

</configuration>

This is my client (Winforms) app.config:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>

<system.web>
  <httpRuntime maxRequestLength="2147483647"/>
</system.web>

<system.serviceModel>
  <client>
    <endpoint address="http://192.168.0.60/Service1.svc" binding="basicHttpBinding"
      bindingConfiguration="BasicHttpBinding_IService1" contract="GPLineItemsService.IService1"
      name="BasicHttpBinding_IService1" />
  </client>

  <bindings>
  <basicHttpBinding>
    <binding name="BasicHttpBinding_IService1" maxBufferPoolSize="2147483647" maxBufferSize="2147483647" maxReceivedMessageSize="2147483647" messageEncoding="Text">
      <readerQuotas maxDepth="2000000" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
    </binding>
  </basicHttpBinding>
</bindings>

  <behaviors>
    <endpointBehaviors>
      <behavior name="GpWebServiceBehavior">
        <dataContractSerializer maxItemsInObjectGraph="2147483647"/>
      </behavior>
    </endpointBehaviors>
  </behaviors>

</system.serviceModel>
</configuration>

This is the client code I use to call the service.

EndpointAddress address = new EndpointAddress(GPWCFEndPointAddress);
BasicHttpBinding binding = new BasicHttpBinding();
GPLineItemsService.Service1Client gpService = new GPLineItemsService.Service1Client(binding, address);
GPLineItemsService.GPItems gpItems = new GPLineItemsService.GPItems();
gpItems = gpService.InsertUpdateLineItemsInGP(dtGPItems);
opResult = gpItems.ErrorGPItems;

All your help will much appreciated. Thanks.

Community
  • 1
  • 1
good-to-know
  • 742
  • 3
  • 15
  • 32

2 Answers2

2

You are creating your own binding in code rather than using the one specified in the config file, so any changes you make in the application config file are essentially ignored.

You can set the maxReceivedMessageSize value in code like this:

binding.MaxReceivedMessageSize = 2147483647;

Which makes your full code block this:

EndpointAddress address = new EndpointAddress(GPWCFEndPointAddress);
BasicHttpBinding binding = new BasicHttpBinding();
binding.MaxReceivedMessageSize = 2147483647;
GPLineItemsService.Service1Client gpService = 
    new GPLineItemsService.Service1Client(binding, address);
GPLineItemsService.GPItems gpItems = new GPLineItemsService.GPItems();
gpItems = gpService.InsertUpdateLineItemsInGP(dtGPItems);
opResult = gpItems.ErrorGPItems;

Alternatively, you can use the binding and endpoint as specified in the config file:

GPLineItemsService.Service1Client gpService = new GPLineItemsService.Service1Client();
GPLineItemsService.GPItems gpItems = new GPLineItemsService.GPItems();
gpItems = gpService.InsertUpdateLineItemsInGP(dtGPItems);
opResult = gpItems.ErrorGPItems;
DavidG
  • 113,891
  • 12
  • 217
  • 223
  • if I used the alternate solution, I got this error: "Could not find default endpoint element that references contract 'GPLineItemsService.IService1' in the ServiceModel client configuration section. This might be because no configuration file was found for your application, or because no endpoint element matching this contract could be found in the client element." – good-to-know Jun 29 '15 at 13:50
  • This `binding.MaxReceivedMessageSize = 2147483647;` works like a charm. Thanks. Please advise me how can make alternate solution work? – good-to-know Jun 29 '15 at 13:51
  • 1
    Error of alternate solution is because of calling the service in a class library and calling the class library from another project. In this case I will need to include the WS configuration settings into the main projects app.config if its a winapp or web.config if its a web app. – good-to-know Jun 29 '15 at 14:07
0

This should be the problem <httpRuntime maxRequestLength="32768"/> Try setting up a bigger value.

Stanimir Dimitrov
  • 1,872
  • 2
  • 20
  • 25
  • Thanks, I've tried,and updated the `maxRequestLength` in the client app.config, also updated the question. It wasn't working. :-( – good-to-know Jun 29 '15 at 11:53