Monday, 13 August 2012

4 – RIA Services Libraries

RIA Service project creates a RIA Services link from the Silverlight client project to the Web project such that the code-generation process will generate code directly into your Silverlight project.

That’s ok but it lacks flexibility in that;

1. if you had a second Silverlight client that wanted to consume the same domain services then you don’t really want to have the code for those domain services generated into both client projects
2. if you had a second web site that wanted to expose the same domain service then you probably want that domain service packaged up into a library in order to reference it in multiple places

The “RIA Services Class Library” project helps with this.
I wanted to experiment with Authentication a little and so it made sense for me to want to have my ultimate solution deployed in IIS ( rather than Cassini ) so the route that I took is;
 

New Website in IIS ( File->New WebSite )
 


New Silverlight Project ( File->Add New Project )


with appropriate settings ( note – no RIA Services link here );


and so now I have a Silverlight application hosted by my website. Next, I’ll add;

WCF RIA Services Class Library ( File->Add New Project )


and so now I have 4 projects in play;




Set up References


I now need to tie the right projects together. My Silverlight project needs to reference my AuthRiaLibrary project and my website needs to reference my AuthRIALibrary.Web project as in the previous picture above so that’s easy enough.

Add a Domain Service


I’m then at the point where I can add a DomainService to my AuthRIALibrary.Web project via the “Add New Item” dialog;


and then adding the minimal code to make that into a “service”;




and then building causes code generation to emit code into my AuthRIALibrary project and ( because it’s referenced from my AuthClient project ) but I also need to ensure that my AuthClient project references System.ServiceModel.DomainServices.Client;



and then I can write some code in my client such as;




but it won’t work because the configuration on my website isn’t right.

Configuring the Web Site

I need to make sure that the RIA Services bits are linked into the configuration on my website so I need to pop open web.config and alter it;




and I can run my tiny bit of code and call the service. There’s a need here to ensure that the website has access to the right assemblies for RIA Services which ( from the docs ) looks to involve making sure you’ve done a;

msiexec /i RiaServices.msi SERVER=TRUE


to drop them into the GAC or that you deploy the relevant assemblies in the bin folder of each web site that needs them.

No comments:

Post a Comment