通过更改在创建 XML 读取器时所使用的 XmlDictionaryReaderQuotas 对象的 MaxArrayLength 属性,可增加此配额

前端之家收集整理的这篇文章主要介绍了通过更改在创建 XML 读取器时所使用的 XmlDictionaryReaderQuotas 对象的 MaxArrayLength 属性,可增加此配额前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

https://social.microsoft.com/Forums/zh-CN/c548f38a-4e9d-486f-b46d-ef3719cd0c26/-xml-xmldictionaryreaderquotas-maxarraylength-?forum=wcfzhchs


http://stackoverflow.com/questions/7470530/problem-with-large-requests-in-wcf


遇到这个问题的时候,一开始按照大部分人说的设置MaxArrayLength的最大值为一个比较大的数,但是发现还是报错,后面折腾了好久找到了办法

简而言之,就是把服务器端的binding 和endpoint 节点的name属性给去掉


现在我的客户端配置文件是:

<?xml version="1.0"?>
<configuration>
<connectionStrings>
<add name="SafetyValveEntity" connectionString="Metadata=res://*/SafetyValve.csdl|res://*/SafetyValve.ssdl|res://*/SafetyValve.msl;provider=System.Data.sqlClient;provider connection string=&quot;Data Source=.\sqlexpress;Initial Catalog=SafetyValve;Integrated Security=False;User Id=sa;Password=Dayawan123;MultipleActiveResultSets=True&quot;" providerName="System.Data.EntityClient"/>
</connectionStrings>
<startup useLegacyV2RuntimeActivationPolicy="true"><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/>
</startup>

<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="BasicHttpBinding_ISafetyValve" closeTimeout="00:01:00"
openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
maxBufferSize="2147483647" maxBufferPoolSize="5242880000" maxReceivedMessageSize="2147483647"
messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered" useDefaultWebProxy="true" >
<readerQuotas maxDepth="32" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="409600"
maxNaMetableCharCount="2147483647" />
<security mode="None">
<transport clientCredentialType="None" proxyCredentialType="None" realm="" />
<message clientCredentialType="UserName" algorithmSuite="Default" />
</security>
</binding>
</basicHttpBinding>
</bindings>
<client>
<endpoint address="http://cc.liicon.com:8003/SafetyValve.svc"
binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_ISafetyValve"
contract="ServiceReference1.ISafetyValve" name="BasicHttpBinding_ISafetyValve" />
</client>
</system.serviceModel>
</configuration>


服务器端的是:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>
<!-- For more information on Entity Framework configuration,visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection,EntityFramework,Version=6.0.0.0,Culture=neutral,PublicKeyToken=b77a5c561934e089" requirePermission="false" />
</configSections>
<system.web>
<compilation debug="true" targetFramework="4.0">
<assemblies>
<add assembly="System.Data.Entity,Version=4.0.0.0,PublicKeyToken=b77a5c561934e089" />
</assemblies>
</compilation>
</system.web>
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding closeTimeout="00:01:00"
openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
maxBufferSize="2147483647" maxBufferPoolSize="5242880000" maxReceivedMessageSize="2147483647"
messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered" useDefaultWebProxy="true" >
<readerQuotas maxDepth="32" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="409600"
maxNaMetableCharCount="2147483647" />
<security mode="None">
<transport clientCredentialType="None" proxyCredentialType="None" realm="" />
<message clientCredentialType="UserName" algorithmSuite="Default" />
</security>
</binding>
</basicHttpBinding>
</bindings>
<client>
<endpoint address="http://cc.liicon.com:8003/SafetyValve.svc"
binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_ISafetyValve"
contract="ServiceReference1.ISafetyValve" />
</client>

<behaviors>
<serviceBehaviors>
<behavior>
<!-- 为避免泄漏元数据信息,请在部署前将以下值设置为 false 并删除上面的元数据终结点 -->
<serviceMetadata httpGetEnabled="true" />
<!-- 要接收故障异常详细信息以进行调试,请将以下值设置为 true。在部署前设置为 false 以避免泄漏异常信息 -->
<serviceDebug includeExceptionDetailInFaults="true" />
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true" />
<!--
若要在调试过程中浏览 Web 应用程序根目录,请将下面的值设置为 True。
在部署之前将该值设置为 False 可避免泄露 Web 应用程序文件夹信息。
-->
<directoryBrowse enabled="true" />
</system.webServer>
<connectionStrings>
<add name="SafetyValveEntities" connectionString="Metadata=res://*/SafetyValve.csdl|res://*/SafetyValve.ssdl|res://*/SafetyValve.msl;provider=System.Data.sqlClient;provider connection string=&quot;data source=.\sqlexpress;initial catalog=SafetyValve;user id=sa;password=Dayawan123;multipleactiveresultsets=True;App=EntityFramework&quot;" providerName="System.Data.EntityClient" />
</connectionStrings>
<entityFramework>
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.sqlConnectionFactory,EntityFramework" />
<providers>
<provider invariantName="System.Data.sqlClient" type="System.Data.Entity.sqlServer.sqlProviderServices,EntityFramework.sqlServer" />
</providers>
</entityFramework>
</configuration>



注意服务器端的binding 和 endpoint 和客户端不同哟,把name去掉了


奇怪的解决办法,但是好歹可以解决

原文链接:https://www.f2er.com/xml/297513.html

猜你在找的XML相关文章