gpt4 book ai didi

wcf - 传入消息的最大消息大小配额 (65536) ....要增加配额,请使用 MaxReceivedMessageSize 属性

转载 作者:行者123 更新时间:2023-12-03 12:02:44 25 4
gpt4 key购买 nike

我遇到了这个我正在尝试处理的疯狂问题。我知道当我们获取大量数据时,我们必须增加客户端 .config 文件的配额,但是如果我的客户端正在向 WCF 服务器发送大量数据,我该怎么办?

当我发送小型输入参数时,它工作正常。不幸的是,当输入变大时,它就会崩溃。

调试器说:

Bad Request, 400;



在跟踪文件上是:

The maximum message size quota for incoming messages (65536) has been exceeded. To increase the quota, use the MaxReceivedMessageSize property on the appropriate binding element.



有没有办法增加服务器端传入数据的配额?如果是这样,如何?

这是我的示例配置相关部分:
<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();

最佳答案

您可以设置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>

以上是一个非常精简的配置文件,但显示了相关部分。重要的部分是您定义绑定(bind)并为其命名,并显式设置与默认值不同的任何值,并在端点元素的 bindingConfiguration 属性中使用该名称。

关于wcf - 传入消息的最大消息大小配额 (65536) ....要增加配额,请使用 MaxReceivedMessageSize 属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8382392/

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