Monthly Archives: August 2010

[Silverlight] Discoverable RIA Services

When they officially released the Silverlight RIA Services, I think they made also a smart move: they changed the name in WCF RIA Services. Why smart? ‘Cause I think this should help people to remember that after all, under the hood, we’ll always find our big friend: the Windows Communication Foundation (WCF for friends. 😉

So, keeping this in mind, there are no reasons why the services can be only reached by my Silverlight Client application (ok, I have all the proxy code generation and all the other stuff for free, but… I don’t care 😀 ). And with a little trick we can allow the RIA Services to expose data with OData, SOAP and JSON format, allowing to be reached from any kind of client (from WinPhone 7, to a java client).

To achieve this we need to add a reference to an assembly and add three rows in our config file.

In our RIA Services project we need to add a reference to the Microsoft.ServiceModel.DomainServices.Hosting assembly (from the WCF RIA Serivces Toolkit) and, in the web.config, the <system.serviceModel> section should look like this:

   1: <system.serviceModel>
   2:     <domainServices>
   3:       <endpoints>
   4:         <add name="OData" type="System.ServiceModel.DomainServices.Hosting.ODataEndpointFactory, System.ServiceModel.DomainServices.Hosting.OData, Version=, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
   5:         <add name="Soap"  type="Microsoft.ServiceModel.DomainServices.Hosting.SoapXmlEndpointFactory, Microsoft.ServiceModel.DomainServices.Hosting, Version=, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
   6:         <add name="JSON"  type="Microsoft.ServiceModel.DomainServices.Hosting.JsonEndpointFactory, Microsoft.ServiceModel.DomainServices.Hosting, Version=, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
   7:       </endpoints>
   8:     </domainServices>
   9:     <serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
  10:   </system.serviceModel>

Now to call our services we need only to navigate to the right address that we’ll compose in this way:

http://<host web address>/<services dir>/[namespace]-[typespace]-[classname].svc





where Services is the directory where I’m hosting all the RIA Services, and BusinessApplication1.Web.DomainService1 is the complete typename of our web service class, where we simply substituted the . (dot) with the –.

And.. that’s all, folks!!!

P & P Windows Phone 7 Developer Guide

A little post to help me to save this important link: the home page of the Developer Guide community site for the upcoming Windows Phone 7 from the Patterns & Practices guys.

Windows Phone guide on Codeplex