Saturday, May 29, 2010

Enabling OData Endpoint When Creating WCF-RIA Services

image

 

When you create a WCF RIA Service using VS.NET 2010 we can easily enable OData endpoint as well.  This can be done just clicking Check-Box. First let see in Action. First create a silverlight application and do not forgot to check Enable WCF RIA Service Check-Box as shown below.

image

Next we need to add/Create Model which will  expose via WCF-RIA Services. We can create Model using EF or LINQ to SQL .  Once you create the model just compile the project so that VS.NET IDE knows the changes we made to our project. (This compilation needed to show Entity  when we create RIA services ).

Next step is to Add Domain Data Service template to our project so that we can create WCF RIA Services .

image 

If you see the below dialog  box we have an options to check and expose the OData Endpoint. 

image

When you check the Expose OData endpoint Check-Box the following changes were made to your project.(Web Project).

1) The following OData endpoint added to your web.config file

image 

2) Next on  each paramaterless query methods  marked [Query[IsDefault=true)]  attribute

image

That is it now compile the project and browse the endpoints from IE. Here WCF RIA Services are created @ runtime you do not find  .SVC file  ( it is created by virtual provider). To access WCF RIA SERVICE and OData Endpoint  here is the URL format which we need to construct .

http://ServerName:portnumber/Projectname-DomainService.svc.  in my case i am running @ local machine so the WCF RIA SERVICE Endpoint is

http://localhost:61411/ExposeOdataWebApplication-AWDomainService.svc

image

and OData Endpoint is http://localhost:61411/ExposeOdataWebApplication-AWDomainService.svc/OData/

image

if you browse http://localhost:61411/ExposeOdataWebApplication-AWDomainService.svc/OData/ProductCategorySet

image

Nandri(Thanks)

SreenivasaRagavan.

No comments: