How can I configure a WCF service to accept a longer parameter list?
When calling a WCF service from Silverlight that works for smaller parameters, but fails for larger ones (with a "400:Bad Request" response), how can you configure the server to accept a larger number of parameters?
Long Version: I am attempting to call a WCF service from Silverlight, and I am passing a List of Guids that contains 2000 Guids. The service call works for up to 1100 (exactly), but anything past that will result in an error. I looked at the response with Fiddler, and I am getting a response code 400 (Bad Request). I believe this to be a configurable parameter, but I am not sure what setting needs to be changed. I am not 100% confident that my config file settings are being applied as I am intending since I don't know how to check programmatically that these settings are being used. However, I have tried setting maxRequestLength, maxQuestyStringLength, and maxUrlLength of the httpRuntime element under system.web to extremely high values with no change. I have set maxReceivedMessageSize, maxBufferPoolSize, and maxBufferSize of the httpTransport element of a custom binding to high values with no effect. I have set maxDepth, maxArrayLength, maxBytesPerRead, maxNameTableCharCount, and maxStringContentLength of the readerQuota element of a basicHttpBinding also with no effect.
If it isn't obvious by now, I am taking random stabs in the dark based on recommendations from several places online, but nothing has had any effect. If someone knows conclusively which attribute I should be setting so that I can try again, I would greatly appreciate some knowledgable advice. Also it would be especially helpful if someone has advice about how I can check programmatically what settings are being used from my config file, that would at least allow me to confirm that the things I have already tried are being applied in the way I think they are.
UPDATE: Looking at the situation a little closer, my problem is very similar to that described in Large WCF web service request failing with (400) HTTP Bad Request. I did not believe that to be the same issue because I set maxReceivedMessageSize as described in the solution and it didn't fix the problem. However, I think that my web.config is not being applied correctly because I just checked the size of the message in fiddler, and the last successful call (1100 Guids) causes the message size to be 65481, and the first failed request happens with message size 65540. That puts it just over the 65536 default limit.
Here is my current web.config serviceModel section:
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="basicHttpBinding" closeTimeout="01:00:00"
openTimeout="01:00:00" receiveTimeout="01:00:00"
sendTimeout="01:00:00" maxBufferPoolSize="2147483647"
maxBufferSize="2147483647" maxReceivedMessageSize="2147483647">
<readerQuotas maxDepth="2147483647"
maxStringContentLength="2147483647"
maxArrayLength="2147483647" />
</binding>
</basicHttpBinding>
</bindings>
<services>
<service behaviorConfiguration="ReportDataServiceBehavior"
name="DSTM.Reporting.ReportDataService">
<endpoint address="" binding="basicHttpBinding"
contract="DSTM.Reporting.IReportDataService" />
<endpoint address="mex" binding="mexHttpBinding"
contract="IMetadataExchange" />
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="ReportDataServiceBehavior">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="true" />
<dataContractSerializer maxItemsInObjectGraph="2147483647" />
</behavior>
开发者_如何学运维 </serviceBehaviors>
</behaviors>
</system.serviceModel>
How can I ensure that my service is using the binding that I am expecting?
You have binding="basicHttpBinding"
in your endpoint declaration, which instructs the service to use the built-in WCF binding BasicHttpBinding. However, it will not use your customized binding unless you add bindingConfiguration="basicHttpBinding"
to reference the specific binding that you have defined. You may also want to change the name of your <binding>
to make it more clear that you are referencing your binding configuration, and not the basicHttpBinding itself.
Are you passing the parameters in the URL as the GET request or using POST request? There is limitation in IIS for the length of the URL for GET request. If that's the case, you can change the webmethod verb to accept POST instead.
精彩评论