In my previous article, I explained:
- What is Odata?
- Use of Odata service
- Limitations of Odata
- Creating basic WCF Odata service using Visual studio 2010.
In this article, I want go into depth about Odata regarding CRUD operation, Custom entity etc.
Before going into depth, it would be better to explain about REST service.
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:
- GET- To request a specific representation of a resource.
- PUT- To create/ update a resource.
- Delete- To delete a resource.
- POST- Submits data to be processed by the identified resource.
- HEAD- Similar to GET, but retrieves only header part and not the body.
Let me to start with OData crud operations.
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 CRUD operations:
- Using entity object.
- DataServiceContext object.
Just like given below:
DataServiceContext context = new DataServiceContext(new Uri("http://localhost:60259/ODataDemoService.svc/"));
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.
- Create/Add operation.
- Retrieve resource/resources from DB.
- Update operation.
Because Silverlight 4 is used, I have used an asynchronous call back. The next version of Silverlight (Silverlight 5) does not require a callback method.
- Delete operation.
In this way we can CRUD operations in WCF Data Service and Silverlight Client.