Issue with Web Service POST

I have a REST web service that converts a HTML table string to CSV format, and returns the file name of the CSV file (GUID).

This operates fine, however when the data posted exceeds 40 KB, the call fails with error 400.

Mr Google has instructed me to set the following variables to their maximum limit within the web.config - maxRequestLength - maxUrl request limit - maxQueryString request limit - maxReceivedMessageSize - maxArrayLength - maxBytesPerRead - maxDepth - maxNameTableCharCount - maxStringContentLength - maxItemsInObjectGraph

I understand that some of these will need to change to ensure proper security however at this point I am solely concerned with getting the WS to accept data over 40 kb.

I have viewed countless posts, and all point to the solution of setting maxReceivedMessageSize. The issue (I think) is that as we use custom routing, which means the web.config properties are ignored (see below for complete web.config). I can confirm this as Microsoft Service Trace Viewer shows the following error:

The maximum message size quota for incoming messages (65536) has been exceeded. To increase the quota, use the MaxReceivedMessageSize property on the appropriate binding element.

I have tried setting MaxReceivedMessageSize programmatically but cannot seem to find a way.

I am fairly new to .NET so if I'm missing any information please let me know.

The slightest smidgen of help would be greatly appreciated!

Thanks guys

<?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/42020.html

上一篇: 配置的maxUrlLength值未被使用

下一篇: 问题与Web服务POST