HTTP Bad Request error when requesting a WCF service contract

前端 未结 5 1098
攒了一身酷
攒了一身酷 2020-12-10 04:01

I have a WCF service with the following configuration:


    
        
            

        
相关标签:
5条回答
  • 2020-12-10 04:28

    Generally this is a problem with the size of the SOAP envelop. Check your binding configuration in order to change MaxBufferPoolSize, MaxReceivedMessageSize to allow huge contents. Remember, you must change both in client and server sides.

    Another issue is the MessageEnconding (another binding parameter), ensure that client and server side are using the same encoding.

    Finally, check the Reader Quotas Properties parameters.

    0 讨论(0)
  • 2020-12-10 04:33

    I think I found out what the problem is.

    If I browse to the URL:

    http://localhost/myservice/contract

    with the WcfTestClient application I can successfully retrieve the service metadata.
    So the error really only occurs when I request the URL through a web browser.

    The HTTP Bad Request error comes from the fact that the browser issues an HTTP GET request where the contents of the message are in the HTTP headers, and the body is empty.
    This is exactly what the WCF mexHttpBinding is complaining about!

    In order to get to the service contract via a web browser you will have to explicitly enable it in the service behavior:

    <serviceBehaviors>
        <behavior name="MetadataEnabled">
            <serviceMetadata httpGetEnabled="true" />
        </behavior>
    </serviceBehaviors>
    

    The URL to request becomes then:

    http://localhost/myservice?wsdl

    So, it turns out I was a little too quick in posting this question. However, I'll keep it anyway just for the record.

    0 讨论(0)
  • 2020-12-10 04:42

    If you are not sure why your WCF code is throwing an error then I highly recommend the MS Service Trace Viewer. It is very helpful in identifying communication and transport issues like this. Take a look at this C# Corner article for more details.

    0 讨论(0)
  • 2020-12-10 04:49

    I was able to fix the "400 Bad Request" problem by switching my WCF service from running off of Visual Studio Development Server to using Local IIS Web server (right click on the project --> properties --> web tab --> radio button under "Servers"). I hope this helps someone out there because it took me two days to figure this one out.

    0 讨论(0)
  • 2020-12-10 04:51

    I had HTTP 400 issues when consuming a HTTPS mex URL from SvcUtil, eventhough httpsGetEnabled was set to true. The error message was miles away from what was really the issue so I'm posting here in case anyone else stumbles upon the same problem.

    I had a self-signed CA certificate (TestRootCA) which was the issuer of the server certificate (localhost). On the client I imported the TestRootCA CER file but I didn't import the CRL (Certificate Revocation List). It seems that when you use a self-signed CA you must also import the CRL, otherwise server authentication fails in strange ways, none of which point you to the real problem. What's worse is that the fail happens during SSL handshake, before the request even reaches your service, so you'll see no errors in WCF trace logs.

    0 讨论(0)
提交回复
热议问题