简体   繁体   English

将 XML 字符串发送到 WCF 时出现“读取 XML 数据时已超出最大字符串内容长度配额 (8192)”错误

[英]"The maximum string content length quota (8192) has been exceeded while reading XML data" error while sending XML string to WCF

I am working with a .NET, C# application which intends to send a long XML string to a WCF Service method for further operation.我正在使用 .NET、C# 应用程序,该应用程序打算将长 XML 字符串发送到 WCF 服务方法以进行进一步操作。 When my application tries to send the XML string to WCF Service in runtime, I am getting a error message :当我的应用程序尝试在运行时将 XML 字符串发送到 WCF 服务时,我收到一条错误消息:

"The formatter threw an exception while trying to deserialize the message: There was an error while trying to deserialize parameter http://tempuri.org/:strProdUserDataXML. The InnerException message was 'There was an error deserializing the object of type System.String. The maximum string content length quota (8192) has been exceeded while reading XML data. This quota may be increased by changing the MaxStringContentLength property on the XmlDictionaryReaderQuotas object used when creating the XML reader. Line 131, position 57.'. Please see InnerException for more details."

My application side web.config I have written the "binding" & "endpoint" as:我的应用程序端 web.config 我已经将“绑定”和“端点”写为:

<binding name="EndPointHTTPGenericPortal" closeTimeout="01:00:00" openTimeout="01:00:00" receiveTimeout="01:00:00" sendTimeout="01:00:00" allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard" maxBufferSize="2147483647" maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647" messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered" useDefaultWebProxy="true">
    <readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
    <security mode="None">
    <message clientCredentialType="UserName" algorithmSuite="Default" />
    </security>
    </binding>

    <endpoint address="http://192.168.140.40/WcfGenericPortal_Service/Service1.svc" binding="basicHttpBinding" bindingConfiguration="EndPointHTTPGenericPortal" contract="IService1" name="EndPointHTTPGenericPortal" behaviorConfiguration="Graph" />

If any body can help me on how to solve this error I will be very much obliged.如果任何机构可以帮助我解决这个错误,我将非常感激。 Thanks to all in advance.提前感谢大家。

Here is an article on MSDN about Reader Quotas . 这是一篇关于读者配额的 MSDN文章。

It appears that one of the reader quotas on your server side is being exceeded. 似乎超出了服务器端的一个读取器配额。

Specifically, maxStringContentLength is being exceeded. 具体来说,超出了maxStringContentLength The default value is 8192 characters for maxStringContentLength which as described by the error message is being exceeded. maxStringContentLength的默认值为8192个字符,正如超出错误消息所述。

But it may not be the best approach to just bump up all the values to the maximum 2147483647 as some others have suggested. 但它可能不是像其他人所建议的那样将所有值提升到最大值2147483647的最佳方法。

As written in the MSDN documentation that I linked: 正如我链接的MSDN文档中所写:

The complexity constraints provide protection from denial of service (DOS) attacks that attempt to use message complexity to tie up endpoint processing resources. 复杂性约束提供了对拒绝服务(DOS)攻击的保护,这些攻击试图使用消息复杂性来绑定端点处理资源。 Other complexity constraints include items such as a maximum element depth and a maximum length for string content within the message. 其他复杂性约束包括诸如消息内的字符串内容的最大元素深度和最大长度的项。

Coupled with the fact that you currently have Security Mode set to None - you may be setting yourself up for some problems. 再加上您目前将安全模式设置为 - 您可能会遇到一些问题。

I got this error and solve by adding this - MaxItemsInObjectGraph property for the service in both the client and the server configuration . 我得到了这个错误,并通过在客户端和服务器配置中添加此服务的MaxItemsInObjectGraph属性来解决。

<dataContractSerializer maxItemsInObjectGraph="2147483647" />

server side 服务器端

<system.serviceModel>
  <behaviors>
    <serviceBehaviors>
      <behavior name="Service.Service1Behavior">
        <dataContractSerializer maxItemsInObjectGraph="2147483647" />
      </behavior>
</system.serviceModel>

Client side 客户端

<behaviors >
  <endpointBehaviors>
    <behavior name="endpointbehaviour">
      <dataContractSerializer maxItemsInObjectGraph="2147483646"/>
    </behavior>
  </endpointBehaviors>
</behaviors>

and don't forget to apply this behavior to EndPoint behaviorConfiguration="endpointbehaviour" 并且不要忘记将此行为应用于EndPoint behaviorConfiguration =“endpointbehaviour”

Client Side Binding 客户端绑定

    <system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="BasicHttpBinding_IService11" closeTimeout="00:01:00"
openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:10:00"
allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
maxBufferPoolSize="2147483647" maxBufferSize="2147483647" maxReceivedMessageSize="2147483647"
textEncoding="utf-8" transferMode="Buffered" useDefaultWebProxy="true"
messageEncoding="Text">
<readerQuotas maxDepth="128" 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>

<behaviors>
<endpointBehaviors>
<behavior name="KAMServiceDistributor">
<dataContractSerializer maxItemsInObjectGraph="2147483647" />
</behavior>
</endpointBehaviors>
</behaviors>
<client>
<endpoint address="http://localhost:1234/xxxx/Service.svc"
binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IService11"
contract="yourservice namespae" name="AnyName" />
</client>
</system.serviceModel>

Service Config File: 服务配置文件:

<system.serviceModel>
<behaviors>


<serviceBehaviors>
<behavior name="ServiceBehaviour">
<serviceDebug includeExceptionDetailInFaults="false" />
<serviceMetadata httpGetEnabled="true" />
<dataContractSerializer ignoreExtensionDataObject="false" maxItemsInObjectGraph="2147483646" />
</behavior>
</serviceBehaviors>
</behaviors>
<bindings>
<basicHttpBinding>
<binding <b>maxReceivedMessageSize="2147483647"</b>>
<readerQuotas maxDepth="128" maxStringContentLength="2147483647" />
</binding>
</basicHttpBinding>
</bindings>
<services>
<service behaviorConfiguration="ServiceBehaviour" name="Service">
<endpoint binding="basicHttpBinding" contract="IService" />
</service>
</services>
</system.serviceModel>

Pinaki Karuri, Pinaki Karuri,

quotas lengths depend not only on the client's configuration - they also depend on the server's one. 配额长度不仅取决于客户端的配置 - 它们还取决于服务器的配置。 Please post your WCF server's web.config so we can shed some light on the problem. 请发布您的WCF服务器的web.config,以便我们可以解释这个问题。 There is a probability you already have the quota set there for 8192 , so the quickest way for you would be to find and increase its value. 您可能已经为8192设置了配额,因此最快的方法是找到并增加其值。

Update 更新

As far as I can see, you are missing 'readerQuotas' node from your server's web.config, so MaxStringContentLength has its value set to default ( 8192 ). 据我所知,您从服务器的web.config中缺少“readerQuotas”节点,因此MaxStringContentLength将其值设置为default( 8192 )。 Please refer to this link for more information: http://msdn.microsoft.com/en-us/library/system.xml.xmldictionaryreaderquotas.maxstringcontentlength.aspx 有关更多信息,请参阅此链接: http//msdn.microsoft.com/en-us/library/system.xml.xmldictionaryreaderquotas.maxstringcontentlength.aspx

Try to set following things in bindings. 尝试在绑定中设置以下内容。

<readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647"
    maxArrayLength="2147483647" maxBytesPerRead="2147483647"
    maxNameTableCharCount="2147483647" />

It has solved my problem. 它解决了我的问题。 For more reference find following link http://blogfornet.com/2013/08/the-maximum-string-content-length-quota-8192-has-been-exceeded-while-reading-xml-data/ 如需更多参考,请访问以下链接http://blogfornet.com/2013/08/the-maximum-string-content-length-quota-8192-has-been-exceeded-while-reading-xml-data/

Check that your Target Framework for the client is the same as that of the service. 检查客户端的Target Framework是否与服务的Target Framework相同。 I had this issue and tried all of the above fixes but that did not work. 我有这个问题,并尝试了所有上述修复,但这没有用。 Checked properties and checked the Target Framework and changed it. 检查属性并检查目标框架并更改它。

Server side服务器端

<system.serviceModel>
    <bindings>
        <basicHttpBinding>
            <binding maxBufferPoolSize="2147483647"
                     maxReceivedMessageSize="2147483647"
                     maxBufferSize="2147483647">
                <readerQuotas maxDepth="200"
                              maxStringContentLength="2147483647"
                              maxArrayLength="16384"
                              maxBytesPerRead="2147483647"
                              maxNameTableCharCount="16384" />
            </binding>
        </basicHttpBinding>
    </bindings>
    <behaviors>
        <serviceBehaviors>
            <behavior name="">
                <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true"/>
                <serviceDebug includeExceptionDetailInFaults="true"/>
            </behavior>
        </serviceBehaviors>
    </behaviors>
    <protocolMapping>
        <add binding="basicHttpsBinding" scheme="https" />
    </protocolMapping>
    <serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true"/>
</system.serviceModel>

Client side客户端

<system.serviceModel>
    <bindings>
        <basicHttpBinding>
            <binding name="BasicHttpBinding_IRequestService" allowCookies="true"
        maxReceivedMessageSize="2147483647"
        maxBufferSize="2147483647"
        maxBufferPoolSize="2147483647">
                <readerQuotas maxDepth="32"
          maxArrayLength="2147483647"
          maxStringContentLength="2147483647"/>
            </binding>
            <binding name="BasicHttpBinding_IAttachmentService" allowCookies="true"
        maxReceivedMessageSize="2147483647"
        maxBufferSize="2147483647"
        maxBufferPoolSize="2147483647">
                <readerQuotas maxDepth="32"
          maxArrayLength="2147483647"
          maxStringContentLength="2147483647"/>
            </binding>
        </basicHttpBinding>
    </bindings>
</system.serviceModel>

暂无
暂无

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

相关问题 “在读取XML数据时已超出最大字符串内容长度配额(8192)”将XML字符串发送到WCF时出错 - “The maximum string content length quota (8192) has been exceeded while reading XML data” error while sending XML string to WCF WCF-读取XML数据时超出了最大字符串内容长度配额(8192) - WCF - The maximum string content length quota (8192) has been exceeded while reading XML data 反序列化类型的对象时发生错误...读取XML数据时超出了最大字符串内容长度配额(8192) - There was an error deserializing the object of type … The maximum string content length quota (8192) has been exceeded while reading XML data WCF:读取XML数据时已超出最大数组长度配额(16384) - WCF: The maximum array length quota (16384) has been exceeded while reading XML data WCF Config修复最大字符串内容长度配额(8192) - WCF Config to fix The maximum string content length quota (8192) has been exceeded WCF - 读取XML数据时已超出最大名称表字符计数配额(16384) - WCF - The maximum nametable character count quota (16384) has been exceeded while reading XML data 读取XML数据时超出了最大字符串内容长度 - The maximum string content length exceeded while reading XML data ServiceStack:读取XML数据时已超出最大数组长度配额(16384) - ServiceStack: The maximum array length quota (16384) has been exceeded while reading XML data 已超过最大字符串内容长度配额(8192)。增加XmlDictionaryReaderQuotas的MaxStringContentLength属性 - The maximum string content length quota (8192) has been exceeded.Increase the MaxStringContentLength property on the XmlDictionaryReaderQuotas 使用Delphi使用WCF - 最大字符串内容长度配额(8192)错误 - Consuming WCF with Delphi - Maximum string content length quota (8192) error
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM