I have a WCF Service and I am able to GET from it but I can’t work out how to PUT to it. I just want to increment a hits field each time the record is used in the client. Here is some of my code.
Interface:
[OperationContract]
[WebInvoke(Method = "PUT",
ResponseFormat = WebMessageFormat.Json,
BodyStyle = WebMessageBodyStyle.Wrapped,
UriTemplate = "IncSMS")]
void IncSMS();
Method:
public void IncSMS()
{
var business =
(from p in _db.Businesses
where p.BusinessID == 1
select p).FirstOrDefault();
business.SMSHits += 1;
_db.SaveChanges();
}
I’m getting “Method not allowed.” In IE, can anyone see what I’m doing wrong???
Cheers,
Mike.
Well, I asked the question and it took me three days to find the answer to something that should have been very simple.
So the question ended up being: How do I add a
Content-Lengthheader to my request???Answer: You can’t add
Content-Lengthto a URI when typed into a browser, “because by default it will perform a GET”!!! To addContent-Lengthto your header you must use a debugging tool, e.g.. Fiddler or build a form or some other type of client!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.