2

I am creating a client-server application using WCF REST services (.Net 4.0) and I see really strange error there. To access the service I use HttpClient class, the code looks like:

public TResponse Post<TRequest, TResponse>(Uri uri, TRequest request)
    using (HttpClient client = new HttpClient())
    {                
        client.TransportSettings.Credentials = CredentialCache.DefaultCredentials;
        client.TransportSettings.ConnectionTimeout = TimeSpan.FromSeconds(200);

        using (HttpResponseMessage response = client.Post(uri, HttpContentExtensions.CreateDataContract(request, null)))
        {
            response.EnsureStatusIsSuccessful();
            return response.Content.ReadAsDataContract<TResponse>();
        }
    }
}

I host my service on IIS7 and when anonymous auth is enabled everything works well, but when I turn on windows auth some random requests (in average 1 of 10) get failed with 400-Bad request status and error message is : Bad Request - Invalid Verb. HTTP Error 400. The request verb is invalid.

What could it be?

And a little update: if fiddler is turned on everything works perfect.

1
  • Can you validate that the Identity Account running the Application Pool has access to look up users/groups? Commented Dec 18, 2012 at 14:27

1 Answer 1

1

I just ran into the same thing here. Quite a mystery really. I don't understand why having fiddler running removes the problem.

I eventually found that the issue was caused the by the "expect continue" header being added to the post. I removed that and the post succeeds instead of the 400 bad request.

Here's a good entry about it: http://blogs.msdn.com/b/jaskis/archive/2009/04/19/asmx-post-request-fails-with-http-400-error-when-content-length-size-increases.aspx

In my case this was apache HTTP Client v4.0 so,

    httpClient.getParams().setBooleanParameter(
            CoreProtocolPNames.USE_EXPECT_CONTINUE, false);

did the trick.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.