C# app.config 中的 maxReceivedMessageSize 和 maxBufferSize

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/14999779/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-10 13:43:58  来源:igfitidea点击:

maxReceivedMessageSize and maxBufferSize in app.config

c#.netwinformswcfservice-model

提问by Vishal I Patil

How to increase maxReceivedMessageSize and maxBufferSize parameters in app.config file to 2000000 before running the application.

如何在运行应用程序之前将 app.config 文件中的 maxReceivedMessageSize 和 maxBufferSize 参数增加到 2000000。

采纳答案by mattytommo

You need to do that on your binding, but you'll need to do it on bothClient andServer. Something like:

你需要做的是在你的约束力,但你需要做的两个客户端服务器。就像是:

<system.serviceModel>
    <bindings>
        <basicHttpBinding>
            <binding maxBufferSize="64000000" maxReceivedMessageSize="64000000" />
        </basicHttpBinding>
    </bindings>
</system.serviceModel>

回答by Jacob

You can do that in your app.config. like that:

你可以在你的 app.config 中做到这一点。像那样:

maxReceivedMessageSize="2147483647" 

(The max value is Int32.MaxValue)

(最大值为Int32.MaxValue

Or in Code:

或者在代码中:

WSHttpBinding binding = new WSHttpBinding();
binding.Name = "MyBinding";
binding.MaxReceivedMessageSize = Int32.MaxValue;

Note:

笔记:

If your service is open to the Wide world, think about security when you increase this value.

如果您的服务对世界开放,则在增加此值时请考虑安全性。

回答by Aki

Easy solution: Check if it works for you..

简单的解决方案:检查它是否适合你..

Goto web.config

转到 web.config

Find binding used by client.

查找客户端使用的绑定。

change as,

改变为,

maxBufferSize="2147483647" maxReceivedMessageSize="2147483647"

maxBufferSize="2147483647" maxReceivedMessageSize="2147483647"

Done.

完毕。

回答by Sunita Badsra

binding name="BindingName" 
maxReceivedMessageSize="2097152" 
maxBufferSize="2097152" 
maxBufferPoolSize="2097152" 

on client side and server side

在客户端和服务器端

回答by D.R.

The currently accepted answer is incorrect. It is NOTrequired to set maxBufferSizeand maxReceivedMessageSizeon the client and the server binding. It depends!

当前接受的答案是不正确的。它要求设置maxBufferSizemaxReceivedMessageSize在客户端和服务器绑定。这取决于!

If your request is too large (i.e., method parameters of the service operation are memory intensive) set the properties on the server-side, if the response is too large (i.e., the method return value of the service operation is memory intensive) set the values on the client-side.

如果你的请求太大(即服务操作的方法参数是内存密集型的)设置服务端的属性,如果响应太大(即服务操作的方法返回值是内存密集型的)设置客户端的值。

For the difference between maxBufferSizeand maxReceivedMessageSizesee MaxBufferSize property?.

maxBufferSizemaxReceivedMessageSize查看MaxBufferSize 属性的区别.

回答by rox

If you are using a custom binding, you can set the values like this:

如果您使用自定义绑定,您可以设置如下值:

<customBinding>
    <binding name="x">
        <httpsTransport maxBufferSize="2147483647" maxReceivedMessageSize="2147483647" />
    </binding>
</customBinding>

回答by Brijesh Kumar Tripathi

Open app.config on client side and add maxBufferSize and maxReceivedMessageSize attributes if it is not available

在客户端打开 app.config 并添加 maxBufferSize 和 maxReceivedMessageSize 属性(如果不可用)

Original

原来的

  <system.serviceModel>
    <bindings>
      <basicHttpBinding>
        <binding name="Service1Soap"/>
      </basicHttpBinding>
    </bindings>

After Edit/Update

编辑/更新后

  <system.serviceModel>
    <bindings>
      <basicHttpBinding>
        <binding name="Service1Soap" maxBufferSize="2147483647" maxReceivedMessageSize="2147483647"/>
      </basicHttpBinding>
    </bindings>