首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >WCF MaxStringContentLength误差

WCF MaxStringContentLength误差
EN

Stack Overflow用户
提问于 2013-07-10 13:00:17
回答 2查看 1.4K关注 0票数 0

我在iis客户端WinForms上做了一个简单的WCF服务服务器端。

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

格式化程序在试图反序列化消息时抛出一个异常:反序列化操作“CreateFolder”的请求消息正文中的错误。读取XML数据时已超出最大字符串内容长度配额(8192)。可以通过更改在创建XML读取器时使用的MaxStringContentLength对象上的XmlDictionaryReaderQuotas属性来增加此配额。第147行,第78号阵地。

客户端app.config:

代码语言:javascript
复制
<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配置:

代码语言:javascript
复制
<?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上运行服务器时,它工作得很好。有什么办法解决这个问题吗?

EN

回答 2

Stack Overflow用户

发布于 2013-07-10 13:12:35

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

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

票数 2
EN

Stack Overflow用户

发布于 2013-07-10 13:10:11

检查您的maxReceiveMessageSize和maxBufferSize

代码语言:javascript
复制
<binding name="BasicHttpBinding_IService1"
             maxReceivedMessageSize="10000000"
             maxBufferSize="10000000">
</binding>

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

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/17571306

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档