[英]WCF Web.config maxReceivedMessageSize
I'm posting a json object with large amount of text. 我正在发布带有大量文本的json对象。
Below is my current web.config
. 以下是我当前的
web.config
。 How should I modify to change message size to post large json? 我应该如何修改以更改消息大小以发布较大的json?
This is urgent, pls reply fast. 这很紧急,请尽快答复。 thanks!
谢谢!
<?xml version="1.0"?>
<configuration>
<appSettings>
<add key="LogPath" value="\Logs\" />
</appSettings>
<connectionStrings>
</connectionStrings>
<system.web>
<httpRuntime maxRequestLength="10000" />
<compilation debug="true" targetFramework="4.0" />
</system.web>
<system.serviceModel>
<client>
<endpoint address="http://api.microsofttranslator.com/V2/soap.svc"
binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_LanguageService"
contract="TranslatorService.LanguageService" name="BasicHttpBinding_LanguageService" />
</client>
<behaviors>
<serviceBehaviors>
<behavior name="">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="false" />
</behavior>
</serviceBehaviors>
<endpointBehaviors>
<behavior name="webby" >
<webHttp/>
</behavior>
</endpointBehaviors>
</behaviors>
<bindings>
<basicHttpBinding>
<binding name="BasicHttpBinding_LanguageService" 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>
<customBinding>
<binding name="AgricultureTradingWebApp.AgricultureWebService.customBinding0" >
<binaryMessageEncoding />
<httpTransport />
</binding>
</customBinding>
</bindings>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true"
multipleSiteBindingsEnabled="true" />
<services>
<service name="AgricultureTradingWebApp.AgricultureWebService">
<endpoint address="" binding="customBinding" bindingConfiguration="AgricultureTradingWebApp.AgricultureWebService.customBinding0"
contract="AgricultureTradingWebApp.AgricultureWebService" />
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
<endpoint address="json"
binding="webHttpBinding"
contract="AgricultureTradingWebApp.AgricultureWebService"
behaviorConfiguration="webby"/>
</service>
</services>
</system.serviceModel>
</configuration>
It looks like you're using REST, which I haven't done before, so there may be some caveats I'm not aware of. 看来您正在使用REST,这是我之前从未做过的,因此可能有一些我不知道的警告。
However, your json endpoint is using the default webHttpBinding
, which has a MaxReceivedMessageSize of 65536. Since you want to increase this, you need to define the webHttpBinding that you want to use in your config file, give it a name, and assign that name to the json endpoint's bindingConfiguration attribute: 但是,您的json端点使用默认的
webHttpBinding
,其MaxReceivedMessageSize为65536。由于要增加此值,因此需要定义要在配置文件中使用的webHttpBinding,为其指定一个名称,然后为其分配该名称。到JSON端点的bindingConfiguration属性:
<bindings>
<webHttpBinding>
<binding name="myWebHttpBinding" closeTimeout="00:01:00"
openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
allowCookies="false" bypassProxyOnLocal="false"
hostNameComparisonMode="StrongWildcard"
maxBufferSize="524288" maxBufferPoolSize="524288"
maxReceivedMessageSize="524288"
transferMode="Buffered"
useDefaultWebProxy="true">
<readerQuotas maxDepth="32" maxStringContentLength=524288"
maxArrayLength="16384"
maxBytesPerRead="4096" maxNameTableCharCount="16384" />
</binding>
</webHttpBinding>
</bindings>
The above is a modified version of the basicHttpBinding you defined. 上面是您定义的basicHttpBinding的修改版本。 I set an arbitrary value for maxReceivedMessageSize (equal to maxBufferSize and maxBufferPoolSize).
我为maxReceivedMessageSize设置了一个任意值(等于maxBufferSize和maxBufferPoolSize)。 I also increased the maxStringContentLength value in the reader quotas.
我还增加了阅读器配额中的maxStringContentLength值。
In your endpoint, assign the binding above to the bindingConfiguration attribute: 在您的端点中,将上面的绑定分配给bindingConfiguration属性:
<endpoint address="json"
binding="webHttpBinding"
bindingConfiguration="myWebHttpBinding"
contract="AgricultureTradingWebApp.AgricultureWebService"
behaviorConfiguration="webby"/>
Also, take note of the warning on the MSDN article regarding MaxReceivedMessageSize: 另外,请注意MSDN文章上有关MaxReceivedMessageSize的警告:
Increasing this value alone is not sufficient in ASP.NET compatible mode. You should also increase the value of httpRuntime
You'll want to modify the values in my example to suit your needs. 您将需要修改我的示例中的值以适合您的需求。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.