4

I get no error when calling my WCF service methods except in one.

This particular method called SaveTemplate() takes an input of byte[].

I am testing this method with a file of size byte[806803], but ending in an error:

WCF - The remote server returned an unexpected response: (400) Bad Request.*

I have gone through several search results I have found on Google and made some change in app.config according to those, but still getting the error :-(

Here is my WCF Service Library's App.Config file:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <system.web>
    <compilation debug="true" />
  </system.web>

  <system.serviceModel>
    <bindings>
      <wsHttpBinding>
        <binding name="wsHttp" maxReceivedMessageSize="50000000" maxBufferPoolSize="50000000"
        messageEncoding="Mtom" >
          <readerQuotas maxDepth="500000000" maxStringContentLength="500000000" maxArrayLength="500000000"
          maxBytesPerRead="500000000" maxNameTableCharCount="500000000" />
          <security mode="None"></security>
        </binding>
      </wsHttpBinding>
    </bindings>

    <services>
      <service behaviorConfiguration="ReportingComponentLibrary.TemplateServiceBehavior"
        name="ReportingComponentLibrary.TemplateService">
        <endpoint address="" binding="wsHttpBinding" contract="ReportingComponentLibrary.ITemplateService" bindingConfiguration="wsHttp" >
          <identity>
            <dns value="localhost" />
          </identity>
        </endpoint>
        <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" ></endpoint>
        <host>
          <baseAddresses>
            <add baseAddress="http://localhost:8080/ReportingComponentLibrary/TemplateService/" />
          </baseAddresses>
        </host>
      </service>

      <service behaviorConfiguration="ReportingComponentLibrary.TemplateServiceBehavior"
        name="ReportingComponentLibrary.TemplateReportService">
        <endpoint address="" binding="wsHttpBinding" contract="ReportingComponentLibrary.ITemplateReportService" bindingConfiguration="wsHttp" >
          <identity>
            <dns value="localhost" />
          </identity>
        </endpoint>
        <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
        <host>
          <baseAddresses>
            <add baseAddress="http://localhost:8080/ReportingComponentLibrary/TemplateReportService/" />
          </baseAddresses>
        </host>
      </service>

    </services>

    <behaviors>
      <serviceBehaviors>
        <behavior name="ReportingComponentLibrary.TemplateServiceBehavior">
          <serviceMetadata httpGetEnabled="True"/>
          <serviceDebug includeExceptionDetailInFaults="True" />
        </behavior>
      </serviceBehaviors>
    </behaviors>
  </system.serviceModel>
</configuration>
user229044
  • 232,980
  • 40
  • 330
  • 338
inutan
  • 10,558
  • 27
  • 84
  • 126

3 Answers3

5

Since you appear to be hosting inside of ASP.NET in IIS, you need to make sure that the request length ASP.NET allows is also set in addition to WCF's various settings. For ASP.NET the setting you're looking for is maxRequestLength on the httpRuntime element. The default for this setting is only 4MB, so that would explain why you run into an issue.

That would look a little something like this for a 512MB maxLength:

<system.web>
    <httpRuntime maxRequestLength="524288" />

    <!-- rest of your config here -->
</system.web>
Drew Marsh
  • 33,111
  • 3
  • 82
  • 100
  • Thanks for your reply. But I am hosting under Windows Service, Do you think I still need to make this change? – inutan Oct 30 '09 at 17:24
  • Also, please let me know if I can remove tag as a whole because I am hosting my WCF Service Library under a windows service. – inutan Oct 30 '09 at 17:30
  • Oh, well then, that changes things entirely. There's definitely no need for in there unless you're hosting inside of ASP.NET. Lemme think about other problems you might have. – Drew Marsh Oct 30 '09 at 17:50
  • I have removed the section from config file, but I am still getting the same error when calling a service method with signature public bool SaveTemplate(string title, byte[] templateDoc, int templateGroupId), I am testing with a byte array of size byte[806803] for second parameter. If you see I have already tried adding Binding Configuration in app.config. Please let me know if I am missing anything there. Thank you! – inutan Nov 02 '09 at 09:56
0

My 50 cents: change the value of the maxRequestLength attribute of the httpRuntime element from 65536 to 2147483647.

0

Thank you for all help!

It was my ignorance that caused me to take so much time to resolve it.

I had failed to update the config file of my Windows Service with the new Binding configuration. Instead, I was just copying a separate config file in Windows Service directory.

Chris B. Behrens
  • 6,255
  • 8
  • 45
  • 71
inutan
  • 10,558
  • 27
  • 84
  • 126
  • 2
    I'm a little confused. I know this was 3 years ago, but I'm having the same issue. How did you resolve this? Do you mean the configuration you posted was not actually saved in your Service, and that after saving it correctly, it ended up working? – Levitikon Feb 07 '12 at 21:10
  • FWIW the accepted answer in this post worked for me. http://stackoverflow.com/questions/784606/large-wcf-web-service-request-failing-with-400-http-bad-request – Dave Ziegler Feb 09 '12 at 15:56