我发布了一个包含大量文本的json对象。
以下是我当前的web.config
。我该如何修改以更改邮件大小以发布大型json?
这很紧急,请快速回复。谢谢!
<?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>
答案 0 :(得分:3)
看起来你正在使用REST,我以前没有做过,所以可能会有一些我不知道的警告。
但是,您的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>
以上是您定义的basicHttpBinding的修改版本。我为maxReceivedMessageSize设置了一个任意值(等于maxBufferSize和maxBufferPoolSize)。我还增加了读者配额中的maxStringContentLength值。
在您的端点中,将上面的绑定分配给bindingConfiguration属性:
<endpoint address="json"
binding="webHttpBinding"
bindingConfiguration="myWebHttpBinding"
contract="AgricultureTradingWebApp.AgricultureWebService"
behaviorConfiguration="webby"/>
另外,请注意有关MaxReceivedMessageSize的MSDN文章中的警告:
Increasing this value alone is not sufficient in ASP.NET compatible mode. You should also increase the value of httpRuntime
您需要修改我的示例中的值以满足您的需求。