[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=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
   5:         <add name="Soap"  type="Microsoft.ServiceModel.DomainServices.Hosting.SoapXmlEndpointFactory, Microsoft.ServiceModel.DomainServices.Hosting, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
   6:         <add name="JSON"  type="Microsoft.ServiceModel.DomainServices.Hosting.JsonEndpointFactory, Microsoft.ServiceModel.DomainServices.Hosting, Version=4.0.0.0, 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

eg:

http://localhost:52878/Services/BusinessApplication1-Web-DomainService1.svc

http://localhost:52878/Services/BusinessApplication1-Web-DomainService1.svc?wsdl

http://localhost:52878/Services/BusinessApplication1-Web-DomainService1.svc/OData/

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!!!

Advertisements

About palutz

Ex-MSFT SDE. Still a freak geek curious about everything. Trying to keep my mind open and to run my own start-up: http://pastesoft.com View all posts by palutz

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: