问题与Web服务POST
我有一个REST Web服务将HTML表格字符串转换为CSV格式,并返回CSV文件(GUID)的文件名。
这可以很好地工作,但是当发布的数据超过40 KB时,调用将失败,并显示错误400。
谷歌先生已经指示我将下列变量设置为web.config中的最大限制 - maxRequestLength - maxUrl请求限制 - maxQueryString请求限制 - maxReceivedMessageSize - maxArrayLength - maxBytesPerRead - maxDepth - maxNameTableCharCount - maxStringContentLength - maxItemsInObjectGraph
我知道其中一些需要改变以确保适当的安全性,但是现在我只关心让WS接受超过40 kb的数据。
我查看了无数帖子,都指向设置maxReceivedMessageSize的解决方案。 问题(我认为)是因为我们使用自定义路由,这意味着web.config属性将被忽略(请参阅下面的完整web.config)。 我可以将此确认为Microsoft Service Trace Viewer显示以下错误:
传入消息的最大消息大小限额(65536)已被超出。 要增加配额,请在适当的绑定元素上使用MaxReceivedMessageSize属性。
我试图以编程方式设置MaxReceivedMessageSize,但似乎无法找到方法。
我对.NET相当陌生,所以如果我错过了任何信息,请告诉我。
最细微的帮助将不胜感激!
多谢你们
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.diagnostics>
<sources>
<source name="System.ServiceModel"
switchValue="Information, ActivityTracing"
propagateActivity="true">
<listeners>
<add name="traceListener"
type="System.Diagnostics.XmlWriterTraceListener"
initializeData= "c:inetpublogsdataToCSV.svclog" />
</listeners>
</source>
</sources>
</system.diagnostics>
<system.web>
<httpRuntime maxRequestLength="2147483647" requestValidationMode="2.0" />
<compilation debug="true" targetFramework="4.0" />
<customErrors mode="Off" />
</system.web>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true">
<add name="UrlRoutingModule" type="System.Web.Routing.UrlRoutingModule, System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
</modules>
<validation validateIntegratedModeConfiguration="false" />
<httpProtocol>
<customHeaders>
<add name="Access-Control-Allow-Origin" value="*" />
</customHeaders>
</httpProtocol>
<security>
<requestFiltering allowDoubleEscaping="true">
<requestLimits maxUrl="2147483647" maxQueryString="2147483647" />
</requestFiltering>
</security>
</system.webServer>
<system.serviceModel>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
<client>
<service behaviorConfiguration="wcfDataToCSV.DefaultBehavior" name="serviceEndpoints">
<endpoint address="" binding="basicHttpBinding" bindingConfiguration="b1" contract="wcfDataToCSV.DefaultContract" behaviorConfiguration="wsServiceEndpointBehavior" />
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
</service>
</client>
<bindings>
<basicHttpBinding>
<binding transferMode="Streamed" name="b1" maxReceivedMessageSize="2147483647">
<security mode="None">
<transport clientCredentialType="Ntlm"/>
</security>
<readerQuotas maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxDepth="2147483647" maxNameTableCharCount="2147483647" maxStringContentLength="2147483647"/>
</binding>
</basicHttpBinding>
</bindings>
<services>
<service behaviorConfiguration="wcfDataToCSV.DefaultBehavior" name="serviceEndpoints">
<endpoint address="" binding="basicHttpBinding" bindingConfiguration="b1" contract="wcfDataToCSV.DefaultContract" behaviorConfiguration="wsServiceEndpointBehavior" />
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="wcfDataToCSV.DefaultBehavior">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="false" />
<dataContractSerializer maxItemsInObjectGraph="2147483646" />
</behavior>
</serviceBehaviors>
<endpointBehaviors>
<behavior name="wsServiceEndpointBehavior">
<webHttp automaticFormatSelectionEnabled="false" helpEnabled="true"/>
<dataContractSerializer maxItemsInObjectGraph="2147483646" />
</behavior>
</endpointBehaviors>
</behaviors>
<standardEndpoints>
<webHttpEndpoint>
<!--
Configure the WCF REST service base address via the global.asax.vb file and the default endpoint
via the attributes on the <standardEndpoint> element below
-->
<standardEndpoint name="" helpEnabled="true" automaticFormatSelectionEnabled="true" />
</webHttpEndpoint>
</standardEndpoints>
</system.serviceModel>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1" />
</runtime>
</configuration>
链接地址: http://www.djcxy.com/p/42019.html