Reputation: 1562
I'm posting a json object with large amount of text.
Below is my current web.config
. How should I modify to change message size to post large 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>
Upvotes: 1
Views: 23144
Reputation: 28540
It looks like you're using REST, which I haven't done before, so there may be some caveats I'm not aware of.
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:
<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. I set an arbitrary value for maxReceivedMessageSize (equal to maxBufferSize and maxBufferPoolSize). I also increased the maxStringContentLength value in the reader quotas.
In your endpoint, assign the binding above to the bindingConfiguration attribute:
<endpoint address="json"
binding="webHttpBinding"
bindingConfiguration="myWebHttpBinding"
contract="AgricultureTradingWebApp.AgricultureWebService"
behaviorConfiguration="webby"/>
Also, take note of the warning on the MSDN article regarding 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.
Upvotes: 3