I recently recorded a Silverlight TV episode where I demoed configuring a RIA Services DomainService to expose SOAP, JSon and OData endpoints. The video went online earlier today and it can be found here.
Oh and be sure to check out for Silverlight TV Episode 28. It’s going to be awesome!! Stay Tuned!
As you all are aware, RIA Services has a great story OM and tooling story for Silverlight.What if you want a mobile application talking to a domain service or an Ajax application? There could be various different reasons why one would want to expose a different endpoint. The great thing is that enabling these endpoints requires minimal changes in your application.
You will need the following components:-
The OData endpoint support is provided out of the box for you. Here is how you can expose an OData Endpoint.
1: [Query(IsDefault=true)]
2: public IQueryable<Book> GetBooks()
3: {
4: return this.ObjectContext.Books.OrderBy(b => b.Title);
5: }
1: <configSections>
2: <sectionGroup name="system.serviceModel">
3: <section name="domainServices"
4: type="System.ServiceModel.DomainServices.Hosting.DomainServicesSection,
5: System.ServiceModel.DomainServices.Hosting,
6: Version=4.0.0.0, Culture=neutral,
7: PublicKeyToken=31BF3856AD364E35"
8: allowDefinition="MachineToApplication"
9: requirePermission="false" />
10:
11: </sectionGroup>
12: </configSections>
13:
1: <domainServices>
2: <endpoints>
3: <add name="OData"
4: type="System.ServiceModel.DomainServices.Hosting.ODataEndpointFactory, System.ServiceModel.DomainServices.Hosting.OData, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
5: </endpoints>
6: </domainServices>
7:
NOTE: The ODATA endpoint has very limited support in V1. There is no Update or LINQ query support in this release.
In my earlier post, I had showed how to configure a domain service for a Windows Phone 7 application. In that post I had used the Soap endpoint. Configuring a soap and JSON endpoint needs the RIA Services toolkit. After you have installed the toolkit, you will need to do the following:-
3:
4: <add name="OData"
5: type="System.ServiceModel.DomainServices.Hosting.ODataEndpointFactory, System.ServiceModel.DomainServices.Hosting.OData, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
6:
7: <add name="soap"
8: type="Microsoft.ServiceModel.DomainServices.Hosting.SoapXmlEndpointFactory, Microsoft.ServiceModel.DomainServices.Hosting, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
9:
10: <add name="JSON"
11: type="Microsoft.ServiceModel.DomainServices.Hosting.JsonEndpointFactory, Microsoft.ServiceModel.DomainServices.Hosting, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
12:
13: </endpoints>
14: </domainServices>
Note: You can use SOAP and Json endpoints to submit.
A domain service is a WCF Service; therefore it has a SVC path. You can now access the three endpoint we exposed using that.
The uri for these endpoints are:-
OData :http://localhost:[portnumber]/[SLprojectName]-Web-[DomainsServiceName].svc/OData/
SOAP: http://localhost:[portnumber]/[SLprojectName]-Web-[DomainsServiceName].svc
JSON: http://localhost:[portnumber]/[SLprojectName]-Web-[DomainsServiceName].svc/JSON/
With these exposed endpoints, you can talk to multiple clients. In the episode above, I used the following clients:-
You can download the source code for the demo from here.
Cheers!!