C# 已处理ProtocolException,最大字符串内容长度配额为8192

C# 已处理ProtocolException,最大字符串内容长度配额为8192,c#,wcf,C#,Wcf,我有一个C#WCF服务和一个C#console应用程序,希望将一个大文件从应用程序传递到WCF。当我传递字符串时,我得到protocolexception,超过了最大字符串内容长度配额(8192),这是正确的。我在Apps.Config中将ReaderQuotas上的MaxStringContentLength更改为一个很大的值,但没有发生任何变化,它仍然会出错。有人知道为什么吗?我是否需要向web.config添加一些内容。我的档案内容如下:- Web.config <?xml vers

我有一个C#WCF服务和一个C#console应用程序,希望将一个大文件从应用程序传递到WCF。当我传递字符串时,我得到protocolexception,超过了最大字符串内容长度配额(8192),这是正确的。我在Apps.Config中将ReaderQuotas上的MaxStringContentLength更改为一个很大的值,但没有发生任何变化,它仍然会出错。有人知道为什么吗?我是否需要向web.config添加一些内容。我的档案内容如下:-

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>

将大字符串从客户端发送到服务时,需要增加服务配置(即web.config)中的限制。例如:

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


给了我想要的东西。

我将它们添加到Web.config项目中,但没有效果,仍然收到相同的问题。我将基于的地址更改为app.config中的地址,但仍然存在相同的问题。任何其他建议请解决;-)