WCF Services

HTTP verbs

HTTP defines methods (sometimes referred to as verbs) to indicate the desired action to be performed on the identified resource. What this resource represents, whether pre-existing data or data that is generated dynamically, depends on the implementation of the server.  I have listed down some of the major HTTP verbs.

MethodDescription
GETRequests a specific representation of a resource. Requests using GET should only retrieve data and should have no other effect. 
PUTUpdate the resource if the URI refers to an already existing resource else create it.
DELETEDeletes the specified resource.
POSTSubmits data to be processed by the identified resource.
HEADSimilar to GET but only retrieves headers and not the body. This is useful for retrieving meta-information written in response headers, without having to transport the entire content.
OPTIONSReturns the HTTP methods that the server supports for the specified URL. This can be used to check the functionality of a web server by requesting '*' instead of a specific resource.

WebInvoke Verbs To Use With Restful WCF Service


// Get an employee by ID - GET - employee/id ( 
 [WebGet(UriTemplate = "/employee/{id}")] )
// Create a new employee - POST - employee 
 [WebInvoke(Method = "POST", UriTemplate = "/employee/{xml}")] )
// Update an employee - PUT - employee/id  
[WebInvoke(Method = "PUT", UriTemplate = "/employee/{xml}")]
// Delete an employee - DELETE - employee/id 
 [WebInvoke(Method = "DELETE", UriTemplate = "/employee/{id}")]
Refer: http://www.codeproject.com/Articles/803409/REST-enabled-WCF-service

No comments:

Post a Comment