Search code examples
c#wcffiddler

Fiddler gives 411 Error on request to WCF Service PUT/POST


I’m getting a 411 error when I send a request to the following:

Interface:

[OperationContract]
[WebInvoke(Method = "POST",
    ResponseFormat = WebMessageFormat.Json,
    BodyStyle = WebMessageBodyStyle.Wrapped,
    UriTemplate = "IncSMS")]
string IncSMS(int ID);

Method:

public void IncSMS(int ID)
{
    var business =
        (from p in _db.Businesses
            where p.BusinessID == ID
            select p).FirstOrDefault();
    business.SMSHits += 1;
    _db.SaveChanges();
}

Can anyone see why I would be getting the error? All the get methods work, I just cant get POST or PUT to work!

Any ideas???

Cheers,

Mike.


Solution

  • There is nothing wrong with the code, I was trying to request a PUT via a browser and that can’t be done. You can test GETs that way but not PUTs. “because by default it will perform a GET”!

    In fiddler you simply type Content-Length: 0 in the “Request Headers” section of the “Request Builder” and it will magically work! As seen near the bottom of this tutorial: http://blog.donnfelker.com/2008/12/04/how-to-rest-services-in-wcf-3-5-part-2-the-post/

    Thanks guys,

    Mike.