How to Configure RIA Services Using Silverlight 4.0 and Without EF

As a newbie to Silverlight, itโ€™s very difficult for me to set up an RIA web service. The examples available on the Internet almost always refer to Entity infrastructure as ORM, but we use NHibernate as our ORM. I know about the Brad Abrams tutorial where he uses NHibernate as an ORM, but most of it goes above my head because I am also new to NHibernate and some of the RIA concepts are not clear to me, for example. DomainService.

I would like to keep it simple first and ignore ORM for now. So, can someone point me in the right direction, how to get the "vanilla" web service coming with Silverlight 4.0 and the latest version of RIA? For example, how can I set a method that returns an integer of 100, and then call the method from my SilverLight application? Also, I'm not sure if this is relevant or not, but the Silverlight application is hosted in ASP.NET MVC 2.

It should be so simple for me, but I'm really struggling with it at the moment.

TIA

David

+3
source share
1 answer

These scenarios (not related to EntityFramework RIA Services with Silverlight) are certainly documented, and I hope to post some blog entries in the near future to cover these scenarios (including how to use NHibernate).

Here is one way to do what you ask for:

Install "Silverlight 4 Tools for Visual Studio 2010" if you havenโ€™t already:

http://www.microsoft.com/downloads/en/details.aspx?FamilyID=b3deb194-ca86-4fb6-a716-b67c2604a139&displaylang=en

Create a new Silverlight navigation application in Visual Studio 2010 (check the box to enable RIA services).

Modify web.config in a web project in the following ways:

In the <system.web> section, add:

<httpModules> <add name="DomainServiceModule" type="System.ServiceModel.DomainServices.Hosting.DomainServiceHttpModule, System.ServiceModel.DomainServices.Hosting, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" /> </httpModules> 

Add <system.serviceModel> as the <system.web> peer:

  <system.serviceModel> <serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" /> </system.serviceModel> 

Add the following links to your web project:

 System.ServiceModel.DomainServices.Hosting System.ServiceModel.DomainServices.Server 

Create a new VanillaDomainService class in a web project that contains your return 100 method:

 [System.ServiceModel.DomainServices.Hosting.EnableClientAccess()] public class VanillaDomainService : System.ServiceModel.DomainServices.Server.DomainService { public int ReturnInteger100() { return 100; } } 

Now, back to the Silverlight application project, in Home.xaml.cs, in the OnNavigatedTo method, call the new RIA Services method (remember that all calls are asynchronous):

  protected override void OnNavigatedTo(NavigationEventArgs e) { SilverlightApplication1.Web.VanillaDomainContext oneVanillaDomainContext = new SilverlightApplication1.Web.VanillaDomainContext(); oneVanillaDomainContext.ReturnInteger100( anInt => MessageBox.Show(anInt.Value.ToString()), null); } 

Now create and run, and it should be.

I tested this code and it worked for me.

+3
source

All Articles