tags:

views:

2474

answers:

2

Hello there,

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>

Please guide me to resolve this error.

Thank you!

A: 

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
Thanks for your reply. But I am hosting under Windows Service, Do you think I still need to make this change?
inutan
Also, please let me know if I can remove <system.Web> tag as a whole because I am hosting my WCF Service Library under a windows service.
inutan
Oh, well then, that changes things entirely. There's definitely no need for <system.web> in there unless you're hosting inside of ASP.NET. Lemme think about other problems you might have.
Drew Marsh
I have removed the <system.web> 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
A: 

Thank you for all help!

It was an ignorance from my side, that took so much time for me to resolve it.

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

inutan