Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

c#

wcf

fiddler

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.


2 Answers

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.

According to the HTTP Standards, 411 means: 10.4.12 411 Length Required

The server refuses to accept the request without a defined Content- Length. The client MAY repeat the request if it adds a valid Content-Length header field containing the length of the message-body in the request message.

So looks like before you can add data via POST/PUT you'd need to have the length of the data specified.

like image 33
taylonr Avatar answered Dec 31 '25 06:12

taylonr



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!