传入消息的最大消息大小配额 (65536) ....要增加配额,请使用 MaxReceivedMessageSize 属性 [英] The max message size quota for incoming messages (65536) ....To increase the quota, use the MaxReceivedMessageSize property

查看:58
本文介绍了传入消息的最大消息大小配额 (65536) ....要增加配额,请使用 MaxReceivedMessageSize 属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I got this crazy problem I'm trying to deal with. I know that when we're getting huge amount of data we must increase the quota on client .config file, but what am I supposed to do if my client is sending huge data "to" the WCF server?

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

It works perfectly normal when I'm sending small sized input parameter. Unfortunately, it breaks down when the input grows bigger.

调试器说:

错误请求,400;

在跟踪文件上是:

传入消息的最大消息大小配额 (65536) 具有被超过了.要增加配额,请使用 MaxReceivedMessageSize适当绑定元素上的属性.

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.

有什么方法可以增加服务器端传入数据的配额?如果是这样,如何?

Is there some way to increase this quota of incomming data on the server side? if so, how?

这是我的示例配置相关部分:

Here's my sample config related parts:

<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> 

这是我的客户端代码(我动态创建):

and here's my client-side code (I create it dynamically):

        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 属性.

You can set the MaxReceivedMessageSize property on the service via the service's config file.

设置客户端的MaxReceivedMessageSize 只影响客户端接收的消息;它对服务收到的消息没有影响.相应地,要允许服务接收大消息,您需要设置服务的配置文件.

Setting the client's MaxReceivedMessageSize only affects messages received by the client; it has no effect on messages received by the service. Correspondingly, to allow the service to receive large messages, you need to set the service's config file.

示例服务配置

<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 属性中使用该名称.

The above is a very stripped down config file, but shows the relevant parts. The important part is that you define the binding and give it a name, and set any values explicitly that are different from the defaults, and use that name in the bindingConfiguration attribute on the endpoint element.

这篇关于传入消息的最大消息大小配额 (65536) ....要增加配额,请使用 MaxReceivedMessageSize 属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆