我遇到了这个我正在努力处理的疯狂问题。我知道当我们获取大量数据时,我们必须增加客户端.config文件的配额,但如果我的客户端向WCF服务器发送大量数据,我应该怎么做?
当我发送小尺寸输入参数时,它完全正常。不幸的是,当输入变大时,它会崩溃。
调试器说:
跟踪文件上的错误请求,400;
是:
传入邮件的最大邮件大小限额(65536) 被超过了。要增加配额,请使用MaxReceivedMessageSize 适当的绑定元素上的属性。
是否有某种方法可以增加服务器端的数据配额?如果是这样,怎么样?
这是我的示例配置相关部分:
<bindings>
<basicHttpBinding>
<binding name="MyBasicHttpBinding"
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="64" 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="MyWcfService">
<endpoint address="http://myservice..."
binding="basicHttpBinding" bindingConfiguration="MyBasicHttpBinding"
name="MyBasicHttpBinding" contract="IMyContract" />
</service>
</services>
这是我的客户端代码(我动态创建):
var binding = new BasicHttpBinding();
binding.MaxBufferPoolSize = 2147483647;
binding.MaxBufferSize = 2147483647;
binding.MaxReceivedMessageSize = 2147483647;
binding.ReaderQuotas.MaxStringContentLength = 2147483647;
binding.ReaderQuotas.MaxArrayLength = 2147483647;
binding.ReaderQuotas.MaxDepth = 2147483647;
binding.ReaderQuotas.MaxBytesPerRead = 2147483647;
var address = new EndpointAddress("http://mylocalservice..");
ChannelFactory<IMyContract> factory = new ChannelFactory<IMyContract>(binding, address);
foreach (OperationDescription op in factory.Endpoint.Contract.Operations)
{
DataContractSerializerOperationBehavior dataContractBehavior =
op.Behaviors.Find<DataContractSerializerOperationBehavior>()
as DataContractSerializerOperationBehavior;
if (dataContractBehavior != null)
{
dataContractBehavior.MaxItemsInObjectGraph = 2147483646;
}
}
public IMyContract MyClientObject = factory.CreateChannel();
答案 0 :(得分:40)
您可以通过服务的配置文件在服务上设置MaxReceivedMessageSize
属性。
设置客户端的MaxReceivedMessageSize
仅影响客户端收到的消息;它对服务收到的消息没有影响。相应地,要允许服务接收大消息,您需要设置服务的配置文件。
示例服务配置
<system.serviceModel>
<bindings>
<wsHttpBinding>
<binding name="MyBinding" maxReceivedMessageSize="2147483647" />
</wsHttpBinding>
</bindings>
<services>
<service name="MyService">
<endpoint address="http://myservice" binding="wsHttpBinding"
bindingConfiguration="MyBinding" contract="IMyServiceContract" />
</service>
</services>
</system.serviceModel>
以上是一个非常精简的配置文件,但显示了相关部分。重要的是您定义绑定并为其指定名称,并显式设置与默认值不同的任何值,并在端点元素的bindingConfiguration属性中使用该名称。
答案 1 :(得分:6)
我的问题在于wcf测试客户端。出于某种原因,它不会使用增加的maxReceivedMessageSize生成客户端配置。我的修复是右键单击&#34;配置文件&#34; - &GT; &#34;使用SvcConfigEditor编辑&#34; - &GT;绑定 - &gt; maxReceivedMessageSize。
答案 2 :(得分:5)
可以通过将以下附加绑定节点添加到配置文件的绑定部分来解决此问题。
<basicHttpBinding>
<binding maxBufferSize="2147483647" maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647">
<readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647" maxArrayLength="2147483647"
maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
</binding>
</basicHttpBinding>