我知道这个问题在这里已被多次询问,但我已经完成了其中的每一个,似乎无法让它为我工作。从我的客户端,我试图传入2字节参数并返回byte []但是当参数很小时它工作正常,它会抛出“WCF服务已超过最大数组长度配额(16384)”。
这是我的客户端web.config:
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="BasicHttpBinding_GenerateDocument" closeTimeout="00:01:00"
openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:10: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="Transport">
<transport clientCredentialType="None" proxyCredentialType="None"
realm="" />
<message clientCredentialType="UserName" algorithmSuite="Default" />
</security>
</binding>
<binding name="BasicHttpBinding_IGenerateDocument" 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="32" maxStringContentLength="8192" maxArrayLength="16384"
maxBytesPerRead="4096" maxNameTableCharCount="16384" />
<security mode="None">
<transport clientCredentialType="None" proxyCredentialType="None"
realm="" />
<message clientCredentialType="UserName" algorithmSuite="Default" />
</security>
</binding>
</basicHttpBinding>
</bindings>
<client>
<endpoint address="http://localhost:6543/GenerateDocument.svc"
binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_GenerateDocument"
contract="NWIS.DocumentGeneratorService.IGenerateDocument" name="NWIS.DocumentGeneratorService.GenerateDocument.svc" />
<endpoint address="http://localhost:6543/GenerateDocument.svc"
binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IGenerateDocument"
contract="DocGenService.IGenerateDocument" name="BasicHttpBinding_IGenerateDocument" />
</client>
</system.serviceModel>
这是服务器等价物:
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="BasicHttpBinding_GenerateDocument" closeTimeout="00:01:00"
openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:10: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="5242880" maxArrayLength="2147483646"
maxBytesPerRead="4096" maxNameTableCharCount="5242880"/>
<security mode="Transport">
<transport clientCredentialType="None" proxyCredentialType="None"
realm="" />
<message clientCredentialType="UserName" algorithmSuite="Default" />
</security>
</binding>
</basicHttpBinding>
</bindings>
<behaviors>
<serviceBehaviors>
<behavior name="ServiceBehaviour">
<!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment -->
<serviceMetadata httpGetEnabled="true" />
<!-- To receive exception details in faults for debugging purposes, set the value below to true. Set to false before deployment to avoid disclosing exception information -->
<serviceDebug includeExceptionDetailInFaults="false" />
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="false" />
<services>
<service name="NWIS.DocumentGeneratorService.GenerateDocument" behaviorConfiguration="ServiceBehaviour">
<host>
<baseAddresses>
<add baseAddress="http://localhost:6543/"/>
</baseAddresses>
</host>
<endpoint address="http://localhost:6543/GenerateDocument.svc" binding="basicHttpBinding"
contract="NWIS.DocumentGeneratorService.IGenerateDocument" />
</service>
</services>
</system.serviceModel>
如果有人能够看到400字节的原因,但不是20000字节,我将不胜感激任何指导。
提前感谢你们
答案 0 :(得分:2)
您已在服务器端使用超大值定义了绑定配置 - 但您没有使用它!
您需要在服务端点中指定要使用的绑定配置!
因此,请将当前配置更改为:
<service name="NWIS.DocumentGeneratorService.GenerateDocument" behaviorConfiguration="ServiceBehaviour">
....
<endpoint
address="http://localhost:6543/GenerateDocument.svc"
binding="basicHttpBinding"
bindingConfiguration="BasicHttpBinding_GenerateDocument" <== add this line here!!
contract="NWIS.DocumentGeneratorService.IGenerateDocument" />
</service>
然后,希望您的服务实际上会使用您配置的那些值!