MiscellaneousUser
MiscellaneousUser

Reputation: 3063

ProtocolException was handled, Max string content length quota 8192

I have a C# WCF service and a C# console application and wish to pass a large file from the application to the WCF. When I pass the string, I get protocolexception, max string content length quota exceeded (8192) which is correct. I change the MaxStringContentLength on ReaderQuotas in the Apps.Config to a large amount but nothing happens, it still errors. Does anyone know why? Do I need to add something to the web.config. The contents of my files are below :-

Web.config

<?xml version="1.0"?>
<configuration>
<system.web>
    <compilation debug="true" targetFramework="4.0"/>
</system.web>
<system.serviceModel>
    <behaviors>
        <serviceBehaviors>
            <behavior>
                <!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment -->
                <serviceMetadata httpGetEnabled="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>
    <serviceHostingEnvironment multipleSiteBindingsEnabled="true"/>
</system.serviceModel>
<system.webServer>
    <modules runAllManagedModulesForAllRequests="true"/>
</system.webServer>
</configuration>

App.Config

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.serviceModel>
    <bindings>
        <basicHttpBinding>
            <binding name="BasicHttpBinding_IService" closeTimeout="00:01:00"
                openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
                allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
                maxBufferSize="65536" maxBufferPoolSize="524288" maxReceivedMessageSize="65536"
                messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered"
                useDefaultWebProxy="true">
                <readerQuotas maxDepth="32" maxStringContentLength="88192" maxArrayLength="16384"
                    maxBytesPerRead="4096" maxNameTableCharCount="16384" />
                <security mode="None">
                    <transport clientCredentialType="None" proxyCredentialType="None"
                        realm="" />
                    <message clientCredentialType="UserName" algorithmSuite="Default" />
                </security>
            </binding>
          <binding name="largeStrings" openTimeout="00:02:00" sendTimeout="00:02:00"
              maxBufferSize="524288" maxReceivedMessageSize="524288">
            <readerQuotas maxDepth="10" maxStringContentLength="524288" maxArrayLength="16384"
             maxBytesPerRead="4096" maxNameTableCharCount="16384" />
          </binding>
        </basicHttpBinding>
    </bindings>
    <client>
        <endpoint address="http://localhost:2745/ActuristDemo/Service.svc"
            binding="basicHttpBinding" bindingConfiguration="largeStrings"
            contract="ActuristWS.IService" name="largeStrings" />
    </client>
</system.serviceModel>
</configuration>

Upvotes: 0

Views: 1253

Answers (2)

Eren Ers&#246;nmez
Eren Ers&#246;nmez

Reputation: 39095

When you're sending the large string from the client to the service, you need to increase the limits in the service configuration (i.e. web.config). Example:

<system.serviceModel>
<bindings>
  <basicHttpBinding>
    <binding name="customHttpBinding" maxBufferSize="2147483647"
        maxReceivedMessageSize="2147483647" />
    <binding name="BasicHttpBinding_IMyWebService" closeTimeout="00:01:00"
        openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
        allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
        maxBufferSize="2147483647" maxBufferPoolSize="524288" maxReceivedMessageSize="2147483647"
        messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered"
        useDefaultWebProxy="true">
      <readerQuotas maxDepth="32" maxStringContentLength="2147483647" maxArrayLength="16384"
          maxBytesPerRead="4096" maxNameTableCharCount="16384" />
      <security mode="None">
        <transport clientCredentialType="None" proxyCredentialType="None"
            realm="" />
        <message clientCredentialType="UserName" algorithmSuite="Default" />
      </security>
    </binding>
  </basicHttpBinding>
</bindings>
<services>
  <service name="MyService.MyWcfService">
    <endpoint address="" binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IMyWebService"
        contract="MyService.IMyWebService" />
    <host>
      <baseAddresses>
        <add baseAddress="http://localhost/MyService/MyWcfService/" />
      </baseAddresses>
    </host>
  </service>
</services>

Upvotes: 0

Related Questions