Open Data Protocol is a web protocol for accessing information via services. It is built upon technologies such as XML and JSON. The main component for building the OData service on .NET Framework is WCF Data Service. OData service can support different data source models including ADO.NET Entity Framework. LINQ to SQL etc. This post outlines the steps to creating an OData service on the .NET Framework through WCF Data service and ADO.NET Entity Framework data model.
1. Open Visual Studio 2012 and create new project by selecting ASP.NET Empty web application template in dialogue box.
2. Add new item from project menu and select ADO.NET Entity Data Model from dialogue box
Choose the database objects in the wizard and say finish.
3. Create a new OData service using WCF Data service template which can be found under web category
4. Open the WcfDataService1.svc.cs file and change the default service type with the entity framework model class as shown below
5. Now start running the service by selecting .svc file in solution explorer and choose the view in browser then result will be as below
6. WCF Data service encapsulates the details of implementing an OData service. What all you need to do is generate data source and associate with the WCF Data Service. WCF Data Service is WCF Service implemented over REST Http endpoint. Most cases we no need to worry about configuration details.
7. You can also expose OData endpoints using WCF RIA service. WCF RIA service is based on standard WCF service and is designed for building data access services and encapsulates the business-logic at service layer. You can expose the data through end-points such as SOAP, OData and JSON.
8. Create a new WCF RIA service by selecting Domain Service Class item template in visual studio new item dialogue box
9. Specify the service options like enabling an OData endpoint.
10. Create a .svc file as the service access endpoint for the WCF RIA Service
Update the servicehost directive with ServiceHostFactory and Service types.
11. Now launch the WCF RIA service and access its OData endpoint by adding the odata suffix to the URL.
12. There is an entry in the web.Config file when you click ok which enables you enter odata in url
|Share this post :|