gpt4 book ai didi

wcf - WCF 中的最大数组长度配额异常

转载 作者:行者123 更新时间:2023-12-04 21:24:33 25 4
gpt4 key购买 nike

我正在编写 WCF 服务来上传文件,但是当字节数组的元素超过 16384 时,它会引发异常。

这是异常详细信息:

The formatter threw an exception while trying to deserialize the message: Error in deserializing body of request message for operation 'CreateDocument'. The maximum array length quota (16384) has been exceeded while reading XML data. This quota may be increased by changing the MaxArrayLength property on the XmlDictionaryReaderQuotas object used when creating the XML reader. Line 1, position 22862.



客户端和服务器的配置将最大数组长度配额设置为 2147483647。

客户端配置:
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="BasicHttpBinding_IDocumentLibraryService" 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="2147483647" maxReceivedMessageSize="2147483647"
messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered"
useDefaultWebProxy="true">
<readerQuotas maxDepth="32" maxStringContentLength="2147483647" maxArrayLength="2147483647"
maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
<security mode="None">
<transport clientCredentialType="None" proxyCredentialType="None"
realm="" />
<message clientCredentialType="UserName" algorithmSuite="Default" />
</security>
</binding>
</basicHttpBinding>
</bindings>
<client>
<endpoint address="http://localhost:50764/DocumentLibraryService.svc"
binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IDocumentLibraryService"
contract="DocumentLibrary.IDocumentLibraryService" name="BasicHttpBinding_IDocumentLibraryService" />
</client>

服务器配置:
<bindings>

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

<service name="BasicHttpBinding_IDocumentLibraryService">

<clear />
<endpoint address="mex" binding="mexHttpBinding" name="mex" contract="Peninsula.DocumentLibrary.ServiceLayer.IDocumentLibraryService" />
<endpoint binding="basicHttpBinding" name="DocumentLibraryService" contract="Peninsula.DocumentLibrary.ServiceLayer.IDocumentLibraryService" address=""
bindingConfiguration="BasicHttpBinding_IDocumentLibraryService"/>
</service>
</services>

最佳答案

我需要做的就是将 web.config 文件中的服务名称更改为带有命名空间的完整服务名称:

<service name="SampleNameSpace.DocumentLibraryService">

<clear />
<endpoint address="mex" binding="mexHttpBinding" name="mex" contract="Peninsula.DocumentLibrary.ServiceLayer.IDocumentLibraryService" />
<endpoint binding="basicHttpBinding" name="DocumentLibraryService" contract="Peninsula.DocumentLibrary.ServiceLayer.IDocumentLibraryService" address=""
bindingConfiguration="BasicHttpBinding_IDocumentLibraryService"/>
</service>

关于wcf - WCF 中的最大数组长度配额异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5896717/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com