0

I am coding a WCF service using json that is currently executing in a console app for debugging/testing. Once completed this WCF service will be executing as a Windows Service. The WCF service will be consumed by a Windows Form app and an Android app.

My latest change added 2 operation contracts that will pass image data in request and reply messages.

During testing of these new operation contracts, if I attempt to pass a large image file, I receive this exception:

'The remote server returned an error: (413) Request Entity Too Large.'

In researching this exception I found lots of threads explaining how to correct it. During my initial debugging/testing, I was not specifying an endpoint in my app.config file. To add the basicHttpBinding information to increase the size limits, I found that I also needed to add an endpoint. Once I did this, I started receiving this exception for ALL of my operation contracts:

System.Net.WebException: 'The remote server returned an error: (400) Bad Request.'

I do not understand why I receiving this 400 Bad Request exception.

Here is the servicemodel section from my app.config.

  <system.serviceModel>
    <bindings>
      <basicHttpBinding>
        <binding name="MyBasic" maxReceivedMessageSize="2147483647" 
                 maxBufferPoolSize="2147483647" maxBufferSize="2147483647" />
      </basicHttpBinding>
    </bindings>
    <services>
      <service name="StampTrackerServiceLibrary.StampTrackerService">
        <endpoint address="http://LocalHost:9091/StampTrackerService" binding="basicHttpBinding"
          bindingConfiguration="MyBasic" contract="StampTrackerServiceLibrary.IStampTrackerServiceLibrary"/>
      </service>
    </services>
  </system.serviceModel>

Can anyone provide any assistance in determining what I am doing incorrectly?

I have researched both 413 and 400 exceptions and attempted to solve my issues.

Steve
  • 11
  • 1
  • 2
  • Sorry, may not be of any help and may depend on how far through you are, but I would feel a WCF windows service is probably the wrong start point considering your wanting to consume this from an android app. Probably better off using a WebAPI rest service – Hursey Mar 23 '23 at 19:32
  • Whether I agree or not, the people way above my pay grade made that decision. However I will say, until this 413/400 exception came up, my library was working in both my console app for Debugging/Testing and as a Windows Service for user acceptance of completed parts without any issues. I just need to figure out how to configure this correctly so I can finish. I'm almost done with my coding of all 3 parts (WCF, Win Form, and Android App). – Steve Mar 23 '23 at 20:47
  • To me, both 400 & 413 errors suggest more an issue with the data being sent from the clients rather than anything server side. If it was working before, without the 400 errors, would revert to that so you can address the 413 issue on it's own. At this point you may need to consider ways to reduce the image size (compression/resolution etc) – Hursey Mar 23 '23 at 22:37
  • The most direct and effective way is to reduce the size of the transferred files. You can test the maximum size of the files that your code can support. – Jiayao Mar 24 '23 at 06:06

1 Answers1

1

Based on this post from 2012

[https://social.msdn.microsoft.com/Forums/vstudio/en-US/8ae01b2c-842c-4a79-a0da-0d635ed9d335/wcf-http-400-bad-request?forum=wcf][1]

I changed my config file to this and things started working.

<system.serviceModel>
  <bindings>
    <webHttpBinding>
      <binding name="MyWeb" maxReceivedMessageSize="2147483647"
               maxBufferPoolSize="2147483647" maxBufferSize="2147483647" />
    </webHttpBinding>
  </bindings>
  <behaviors>
    <serviceBehaviors>
      <behavior name="MyBeh">
        <serviceMetadata httpGetEnabled="true"/>
      </behavior>
    </serviceBehaviors>
  </behaviors>
  <services>
    <service name="StampTrackerServiceLibrary.StampTrackerService" behaviorConfiguration="MyBeh">
      <endpoint address=" " bindingConfiguration="MyWeb"
          binding="webHttpBinding" contract="StampTrackerServiceLibrary.IStampTrackerServiceLibrary" />
      <endpoint address="mex "
          binding="webHttpBinding" bindingConfiguration="" contract="IMetadataExchange" />
    </service>
  </services>
</system.serviceModel>
Steve
  • 11
  • 1
  • 2