CRUD Operations With WCF Odata Service

In my previous article, I explained the following:
  • What is Odata?
  • Use of Odata service.
  • Limitations of Odata.
  • Creating basic WCF Odata service using Visual studio 2010.
In this article, I won't go into the depth of Odata regarding CRUD operation, Custom entity etc. Before going into depth, it would be better to explain about REST services.
Representational state transfer (REST) is a style of software architecture for World Wide Web. The cool thing about REST is that it is not tied to any particular technology or platform. The term is often used in a looser sense to describe any simple interface which transmits domain-specific data over HTTP without an additional messaging layer such as SOAP or session tracking via HTTP cookies. A RESTFUl web service is a simple web service implemented using HTTP and the principles of REST. Such a web service can be thought of as a collection of resources. The MIME type of the data is supported by the web service. This is often JSON, XML but can be anything. The set of operations are supported by the web service using HTTP methods (e.g. POST, GET, PUT or DELETE).

WCF Rest Services

WCF Rest Services are normal WCF Services that have added functionality so that they can be consumed in a RESTful manner.
HTTP Verbs supported by WCF Data services are:
  1. GET-To request a specific representation of a resource.
  2. PUT-To create/ update a resource.
  3. Delete-To delete a resource.
  4. POST-Submits data to be processed by the identified resource.
  5. HEAD- Similar to GET, but retrieves only header part and not the body.
Let me start with OData crud operation.
I have created one OdataDemo Silverlight application. So, I am going to start with Create/Add new resource to the entity and DB. There are two ways to do a CRUD operation:
  1. Using entity object.
  2. DataServiceContext object.
Just like given below:
  1. DataServiceContext context = new DataServiceContext(new Uri("http://localhost:60259/ODataDemoService.svc/"));  
  2. ODataDemoEntities ObjEntity = new ODataDemoEntities(new Uri("http://localhost:60259/ODataDemoService.svc/"));  
I have written code for both using an entity as well as a datacontext object.
  1. Create/Add operation

  2. Retrieve resource/resources from DB

  3. Update operation

  4. Delete operation

In this way, we can do CRUD operations in a WCF Data Service and a Silverlight Client.

Similar Articles