C# WCF MaxStringContentLength错误

C# WCF MaxStringContentLength错误,c#,wcf,C#,Wcf,我正在制作简单的WCF服务 在iis上运行的服务器端 客户端WinForms 当我尝试向服务器发送大字符串时,出现以下异常: 格式化程序在尝试反序列化 消息:反序列化操作的请求消息正文时出错 “CreateFolder”。已设置最大字符串内容长度配额(8192) 读取XML数据时已超过。这一配额可增加10% 更改服务器上的MaxStringContentLength属性 创建XML读取器时使用的XmlDictionaryReaderQuotas对象。 第147行,第78位 客户端app.conf

我正在制作简单的WCF服务 在iis上运行的服务器端 客户端WinForms

当我尝试向服务器发送大字符串时,出现以下异常:

格式化程序在尝试反序列化 消息:反序列化操作的请求消息正文时出错 “CreateFolder”。已设置最大字符串内容长度配额(8192) 读取XML数据时已超过。这一配额可增加10% 更改服务器上的MaxStringContentLength属性 创建XML读取器时使用的XmlDictionaryReaderQuotas对象。 第147行,第78位

客户端app.config:

<configuration>
  <system.serviceModel>
    <bindings>
      <basicHttpBinding>
        <binding name="BasicHttpBinding_IService1" maxReceivedMessageSize="10000000" >
          <readerQuotas maxDepth="32" maxStringContentLength="10000000"   maxArrayLength="16384"
                    maxBytesPerRead="4096" maxNameTableCharCount="16384" />
        </binding>
      </basicHttpBinding>
    </bindings>
    <client>
      <endpoint address="http://192.168.15.72:7777/Service1.svc" binding="basicHttpBinding"
        bindingConfiguration="BasicHttpBinding_IService1" contract="ServiceReference1.IService1"
        name="BasicHttpBinding_IService1" />
    </client>
  </system.serviceModel>
</configuration>

服务器Web配置:

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

  <system.web>
    <compilation debug="true" targetFramework="4.0" />
  </system.web>
  <system.serviceModel>
    <bindings>
      <basicHttpBinding>
        <binding name="BasicHttpBinding_IService1" maxReceivedMessageSize="10000000"
        maxBufferSize="10000000" >
          <readerQuotas maxDepth="32" maxStringContentLength="10000000"   maxArrayLength="16384"
                     maxBytesPerRead="4096" maxNameTableCharCount="16384" />
        </binding>
      </basicHttpBinding>
    </bindings>
    <services>
      <service name="WCFService">
        <endpoint address="" binding="basicHttpBinding"
          bindingConfiguration="BasicHttpBinding_IService1" contract="ServiceReference1.IService1"
          name="BasicHttpBinding_IService1">
        </endpoint>
      </service>
    </services>
    <behaviors>
      <serviceBehaviors>
        <behavior>
          <serviceMetadata httpGetEnabled="true"/>
          <serviceDebug includeExceptionDetailInFaults="false"/>
        </behavior>
      </serviceBehaviors>
    </behaviors>

    <serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
  </system.serviceModel>
  <appSettings>
    <add key="PathToSafe" value="D:\Temp"/>
  </appSettings>
 <system.webServer>
    <modules runAllManagedModulesForAllRequests="true"/>
  </system.webServer>

</configuration>

当我在本地主机iis上运行服务器时,它工作得非常好。
有什么办法解决这个问题吗?

检查您的maxReceiveMessageSize和maxBufferSize

<binding name="BasicHttpBinding_IService1"
             maxReceivedMessageSize="10000000"
             maxBufferSize="10000000">
</binding>


它们应该足够大,以允许您的较大字符串+消息中的其他内容

绑定同时适用于客户端和服务。您正确地修改了客户端,但也需要在服务器端进行修改


客户端向服务器发送请求-服务器正在进行反序列化,而您的错误在反序列化时发生。所有内容都指出您没有更新绑定的服务器端配置(web.config)

replice-possible查看此处的链接,请注意,如果您没有将该绑定定义分配给端点(通过
端点
元素上的
bindingConfiguration
属性),更改将不会生效。将使用终结点的指定绑定的默认值。您能告诉我该如何配置它吗?我不知道怎么做找到web.config文件。找到“bindings\basicHttpBinding”部分,并将“binding”节点从客户端复制粘贴到服务中找到的匹配节点上。如果你仍然不确定-复制/粘贴web.config并更新你的帖子,我会发布一个答案,它应该是什么样子。。。