Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/269.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# &引用;读取XML数据时已超过最大字符串内容长度配额(8192)";向WCF发送XML字符串时出错_C#_.net_Wcf_Web Config_Quota - Fatal编程技术网

C# &引用;读取XML数据时已超过最大字符串内容长度配额(8192)";向WCF发送XML字符串时出错

C# &引用;读取XML数据时已超过最大字符串内容长度配额(8192)";向WCF发送XML字符串时出错,c#,.net,wcf,web-config,quota,C#,.net,Wcf,Web Config,Quota,我正在使用一个.NET C#应用程序,它打算向WCF服务方法发送一个长XML字符串,以便进行进一步的操作。当我的应用程序尝试在运行时将XML字符串发送到WCF服务时,我收到一条错误消息: “格式化程序在尝试反序列化消息时引发异常:尝试反序列化参数时出错http://tempuri.org/:strProdUserDataXML. InnerException消息为“反序列化System.String类型的对象时出错。最大字符串内容长度配额(8192)读取XML数据时已超过。可以通过更改创建XML

我正在使用一个.NET C#应用程序,它打算向WCF服务方法发送一个长XML字符串,以便进行进一步的操作。当我的应用程序尝试在运行时将XML字符串发送到WCF服务时,我收到一条错误消息:

“格式化程序在尝试反序列化消息时引发异常:尝试反序列化参数时出错http://tempuri.org/:strProdUserDataXML. InnerException消息为“反序列化System.String类型的对象时出错。最大字符串内容长度配额(8192)读取XML数据时已超过。可以通过更改创建XML读取器时使用的XmlDictionaryReaderQuotas对象的MaxStringContentLength属性来增加此配额。第131行,位置57。“。有关详细信息,请参阅InnerException。”

我的应用程序端web.config我已将“绑定”和“端点”编写为:


如果有人能帮助我解决这个错误,我将不胜感激。 感谢所有的一切。皮纳基·卡鲁里

配额长度不仅取决于客户端的配置,还取决于服务器的配置。请发布您的WCF服务器的web.config,这样我们就可以了解这个问题。您很可能已经为8192设置了配额,因此最快的方法是找到并增加其值

更新


据我所知,服务器的web.config中缺少“readerQuotas”节点,因此MaxStringContentLength将其值设置为默认值(8192)。有关详细信息,请参阅此链接:

我收到了此错误,并通过在客户端和服务器配置中为服务添加此-MaxItemsInObjectGraph属性来解决

<dataContractSerializer maxItemsInObjectGraph="2147483647" />

服务器端

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

客户端

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


不要忘记将此行为应用于EndPoint behavior Configuration=“EndpointBehavior”

尝试在绑定中设置以下内容

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


它解决了我的问题。有关更多参考,请查看以下链接

这里是一篇关于MSDN的文章

似乎超出了服务器端的某个读卡器配额

具体地说,正在超过maxStringContentLength。默认值为maxStringContentLength8192个字符,超出了错误消息所述的值

但是,正如一些人所建议的那样,将所有值提升到最大值2147483647可能不是最好的方法

正如我链接的MSDN文档中所述:

复杂性约束提供了防止拒绝服务的保护 (DOS)试图利用消息复杂性来捆绑的攻击 端点处理资源。其他复杂性约束包括 项目,例如最大元素深度和字符串的最大长度 消息中的内容


再加上您当前的安全模式设置为,您可能设置了一些问题。

检查您的客户端目标框架是否与服务的目标框架相同。我有这个问题,并尝试了上述所有修复,但没有工作。检查属性并检查目标框架并对其进行更改。

客户端绑定

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

服务配置文件:

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


您的服务器端web配置是什么?服务器端最大字符串内容长度配额的值是什么?这里是一个相关的Q&a Hi-Voo&Jocke,感谢您的回复。服务器端配置为:''您的'readerQuotas'节点在哪里?嗨,Piotr Justyana,谢谢您的回复。服务器配置为:''请阅读我的更新答案和我在您的问题下的最后一条评论。谢谢Piotr Justyana,成功了!!!!!你很容易就解决了…非常感谢你的链接帮助我很容易地解决了这个问题,而这正成为我的噩梦。谢谢德里克W的帮助。它帮助我解决了这个问题。我将最大值设置为2147483647,它成功了。我花了不到几个小时来解决问题。您的解决方案帮助我修复了它,谢谢该链接现在转到保留页。筛选完所有答案后,您的答案对我有效..万分感谢您。是的,此答案是其他答案中最有用的,因为它显示了放置读者配额设置的位置!
<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>