Building a .NET RIA service project as a Silverlight class library

by Tom 30. June 2009 09:56

I’ve spent a lot of time over the past few days playing with the new .NET RIA services which can be installed alongside Silverlight 3. RIA services are great, and one thing I’m really liking is how much old code I’ll be able to throw away (like stacks of custom WCF wrappers on the Silverlight side to manage async state and batching multiple service requests).

The original pressure for my team to adopt RIA services was mainly driven by the nice end-to-end data validation framework that it ships with. We started rolling our own and it quickly became clear how much work it was going to take, and – let’s be fair – nobody likes writing that sort of code. If you haven’t checked it out already, a good place to start is over at Brad Abrams’ blog.

A key goal of RIA services is to simplify n-tier architectures, and it does this by creating a link between a ASP.NET web application project and a Silverlight application project and generating a lot of code that is magically shared between the two. I won’t go into this in any detail, because it’s not the point of this post.

One of the big issues I hit first up is this: once you install the RIA services pack, you are given the ability to link a ASP.NET web application project with a Silverlight application, but not a Silverlight class library. My particular usage scenario means I need to share a service DLL  amongst a bunch of XAPs (i.e. modules of a Prism solution) , so it’s no good for me to have a direct link between the RIA services web app and a Silverlight app (e.g. the Prism shell). I need a library I can share between all my modules.

When you create a new web application project, you get the following option:

1

Alternatively, you can go into the properties of a Silverlight application and link the server project there:

2

But strangely enough, these options don’t exist when you are dealing with a Silverlight class library.

The work around is this: create you ASP.NET web application and then create your Silverlight class library. The two aren’t linked yet. Exit visual studio and open the .csproj file of the class library project. You want to add the following:

<PropertyGroup>
	....
	<LinkedServerProject>..\SilverlightApplication1.Web\SilverlightApplication1.Web.csproj</LinkedServerProject>
	...
</PropertyGroup>

Just make sure the path points to your web application project.

Now when you re-open visual studio and build your web application project (assuming it has some domain service classes in it) you’ll see the generated code in your Silverlight class library.

I should probably note that this will all probably change by the time the July CTP comes out (Brad Abrams implied as much in a twitter response to my question).

Categories: Work

Comments

cooolest games
cooolest games United States on 8/6/2009 6:43:10 AM

Just subscribed to your RSS Feed, hopefully you poduce mode great Info in the future.

Jessica
Jessica United States on 8/6/2009 6:43:15 AM

oi oi everyweekend i get on the web

Daly City Marriage Records
Daly City Marriage Records on 11/27/2009 8:37:51 AM

I do not really have a great deal to say in retort, I only wanted to add this comment to say tremendous work. It looks that you have really put a good amount of effort into your post and I need much more of these on the Internet these days. The both of us genuinely enjoyed your article.

Niche Blueprint 2.0 Review
Niche Blueprint 2.0 Review United States on 12/30/2009 9:40:40 PM

I love reading your posts. I wish you a Happy New Year!

Buenos Aires real estate
Buenos Aires real estate United States on 1/21/2010 3:01:16 PM

Thanks for sharing this code with us Smile

Add comment


(Will show your Gravatar icon)

  Country flag

biuquote
  • Comment
  • Preview
Loading