Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WebInvoke Method=“POST” or "GET" for a REST Service on WCF

Tags:

wcf

When should use post vs get? in a REST service on WCF?, below is my interface

       [OperationContract]
       [WebInvoke(Method = "POST", BodyStyle = WebMessageBodyStyle.Wrapped, ResponseFormat = WebMessageFormat.Json)]
       string DoLodge(string Id, Lodge value);

       [OperationContract]
       [WebInvoke(Method = "POST", BodyStyle = WebMessageBodyStyle.Wrapped, ResponseFormat = WebMessageFormat.Json)]
       LodgeLevel[] GetLodgeLevels(string Id);

       [OperationContract]
       [WebInvoke(Method = "POST", BodyStyle = WebMessageBodyStyle.Wrapped, ResponseFormat = WebMessageFormat.Json)]
       long GetLodgeCount(string Id);
like image 527
Nick Kahn Avatar asked Nov 16 '10 19:11

Nick Kahn


People also ask

What is WebInvoke method in WCF?

The WebInvoke attribute exposes services using other HTTP verbs such as POST, PUT, and DELETE. The default is to use POST, but it can be changed by setting the Method property of the attribute. These operations are meant to modify resources; therefore, the WebInvoke attribute is used to make modifications to resources.

Which WCF attribute is used to define RESTful services?

WCF has the option to send the response in JSON object. This can be configured with the WebGet or WebInvoke attribute and the WebHttpBinding. This allows you to expose a ServiceContract as a REST service that can be invoked using either JSON or plain XML.


1 Answers

POST should be used when sending an update back to the server.

GET should be used when retrieving an object from the server.

You might want to read up on what the HTTP Verbs mean in the context of RESTful services:

  • http://swdeveloper.wordpress.com/2012/03/04/rest-for-the-rest-of-us/
  • http://homepages.tig.com.au/~ijoyner/Ian_Joyner/REST.html
like image 180
Justin Niessner Avatar answered Sep 21 '22 06:09

Justin Niessner