简体   繁体   English

WCF MaxStringContentLength错误

[英]WCF MaxStringContentLength error

I making simple WCF service Server Side running on iis Client WinForms. 我在iis Client WinForms上运行简单的WCF服务服务器端。

When I trying to send big string to server i have following exception: 当我尝试将大字符串发送到服务器时,我有以下异常:

The formatter threw an exception while trying to deserialize the message: Error in deserializing body of request message for operation 'CreateFolder'. 格式化程序在尝试反序列化消息时抛出异常:反序列化操作“CreateFolder”的请求消息体时出错。 The maximum string content length quota (8192) has been exceeded while reading XML data. 读取XML数据时已超出最大字符串内容长度配额(8192)。 This quota may be increased by changing the MaxStringContentLength property on the XmlDictionaryReaderQuotas object used when creating the XML reader. 通过更改创建XML阅读器时使用的XmlDictionaryReaderQuotas对象的MaxStringContentLength属性,可以增加此配额。 Line 147, position 78. 第147行,第78位。

client app.config: 客户端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>

Server Web config: 服务器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>

When i run server on localhost iis it works great. 当我在localhost iis上运行服务器时,它运行良好。 Any ideas how to solve this? 任何想法如何解决这个问题?

The binding applies to both client and service. 绑定适用于客户端和服务。 You modified the client side correctly, but you need to do it on the server side as well. 您正确修改了客户端,但您也需要在服务器端执行此操作。

The client sends request to server - server is doing deserialization, and your error occurs while deserializing. 客户端向服务器发送请求 - 服务器正在进行反序列化,并且在反序列化时发生错误。 Everything points out that you didn't update server-side config for binding (web.config) 一切都指出你没有更新服务器端配置绑定(web.config)

check your maxReceiveMessageSize and maxBufferSize 检查你的maxReceiveMessageSize和maxBufferSize

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

they should be sufficiently large to allow your larger strings + what else is in your message 它们应该足够大,以允许你的更大的字符串+你的消息中的其他内容

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM