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!!
Error 1 The "CreateRiaClientFilesTask" task failed unexpectedly.
System.Web.HttpException (0x80004005): Could not load file or assembly 'Microsoft.Web.DomainServices.WebControls, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. Strong name signature could not be verified.
The workaround:
In the SilverlightStore.Web project, from the References folder removeMicrosoft.Web.DomainServices.WebControls. This reference points to the Microsoft.Web.DomainServices.WebControls.dll file in the Lib folder. Add a reference to Microsoft.Web.DomainServices.WebControls found in the c:\program files\microsoft sdks\... on local machine
This is great, thanks... can you tell me how I then configure all the DataServiceConfiguration properties that I normally would in DateService<T>.InitializeService when using oData in the 'normal' way?
This is fantastic stuff guys. Keep up the good work on the toolkit. Thank you very much for adding the Json endpoint factory, it's turned out to be the best part of RIA for me.
Hello
I had installed all the latest updates required for OData,SOAP, JSON endpoints. But when i run the sample application for odata, i am getting an Error Stating
"Service Endpoint Not Fount". Can you please let me know what could be reason for this?
Note: I tried running another sample application from net that expose odata endpoint, it was able to show me the atompub. The same when i tried executing all the steps, i am shown "Endpoint not found"
regards
Dhinesh Kumar
@Dhinesh - do you have the RIA Services Toolkit installed?
The demo source code's web.config has an invalid element.
<system.serviceModel>
<domainServices>
I get a squigly under <domainServices> with the tooltip:
The element 'system.serviceModel' has invalid child element 'domainServices'.
I just installed the April 2010 RIA Services Toolkit.
I have a reference to System.ServiceModel.DomainServices.Hosting in my web project.
I have the section group as above.
Has the system.serviceModel changes recently?
If yes, what would be the correct elements to add a soap endpoint?
Thanks...Ron Lemire
Hi Deepesh,
Is there a way to use soap or json end points together with the authentication services provided by ria services?
I have a winforms app which I want to connect to my domain service using the authentication I have already set up in my RIA services project.
I am wondering whether there is a good way to use Client Application Services? Unfortunately I cannot find any documentation about this.
Many thanks,
Matt
@Ron - did you manage to fix this problem? I'm having the same issue.
Hi jasonxz, any is idea for this problem?
Ron, Jasonxz, Ingphillip,
I'm getting the same error. find a solution to this?
I've got the dll referenced, the configSection correct, but it simply won't validate the domainServices element. >:
you also need a reference to:
c:\Program Files\Microsoft SDKs\RIA Services\v1.0\Libraries\Server\System.ServiceModel.DomainServices.Server.dll
be advised that the *.DomainServices.Hosting.dll that you need to reference is in the \v1.0\TOOLKIT\Libraries\ folder. (in case you see the non-toolkit version and think you've got it referenced already)
In another post you talked about WCF webservices and performance in Silverlight 3
suggesting that binary encoding over http was a good bet.
msdn.microsoft.com/.../ee294456.aspx -
Could you show us the custom binding - all the configuration- for RIA and WP7 using basicHTTP, SOAP and binary encoding? - WP7 needs all the performance it can get
This is good stuff.. But could you also talk about authentication, roles and profiles to make it seamless in other clients including Windows Phone with RIA Services. Is there a resource for it yet?
Hi Abani,
My posts series talk about opening a RIA Services layer to other types of clients (WP7, WPF, HTML5): blogs.msdn.com/.../how-to-open-a-wcf-ria-services-application-to-other-type-of-clients-review-of-the-initial-application-1-5.aspx
It also covers the authentication part.
Regards,
David Rousset
http://blogs.msdn.com/davrous