WCF Service returns 400 Bad Request

后端 未结 3 910
感动是毒
感动是毒 2021-01-19 20:25

I\'ve got this application that works locally and when deployed and using a .mdf SQL Express database file (which I usually use for testing purposes). However, when I change

相关标签:
3条回答
  • 2021-01-19 21:10

    A database connection from a hosted WCF Service is considered a remote connection so make sure your connection strings specifies the authentication method. So try using Integrated Security=SSPI in your connection string and if that doesn't work make sure that your Application Pool's Identity is set to a domain account that has permissions on the SQL server. :)

    0 讨论(0)
  • 2021-01-19 21:10

    This could be that you are making a POST but the service is expecting a GET.

    Try specifying that the method should be a POST:

    [WebInvoke(Method = "POST", UriTemplate = "", ResponseFormat = WebMessageFormat.Json)]
    

    The other this that it could be is that you are using a trusted connection. This means that the security context is the identity of the application pool (if defaults are used). Then you will be making a connection to the database using a local account that does not have access on a database on a different machine.

    The strange thing is that based on the error message it should be the first explaination, but based on your description it would be the second.

    0 讨论(0)
  • 2021-01-19 21:23

    You're probably not setting HTTP headers exactly as the service is expecting them, or in the order it's expecting them.

    Here's how I'd debug it:

    1. Create a quick test client using SvcUtil.exe.
    2. Install Fiddler, turn it on.
    3. Use the thin client to make a call to the service operation.
    4. Use your web application to make a call to the same service operation
    5. Look at the full HTTP request in Fiddler for each request. Compare them. Figure out where your AJAX call is different, and resolve the differences so it matches what the generated client uses.
    0 讨论(0)
提交回复
热议问题