OpenLightGroup Blog

rss

Blogs from OpenLightGroup.net


Using RIA Services with the ASP.Net Web Site Project (WSP) template

Maybe I am a bit to “old school” but I still prefer to use the ASP.Net Web Site project type as opposed to the ASP.Net Web Application project type. I believe this comes from the time spent developing Classic ASP sites and being used to the more “Windows-Like” development of WAP. I am not saying that I will not eventually switch to the “Dark Side” and honestly I already have embraced the Compiled Module project template for my recent DotNetNuke development. However, for now I still have several existing ASP.Net Web Sites that are in use and will not be changing to the compiled project paradigm anytime soon.

This has never been an issue and I had never even considered it to be a drawback until I started learning RIA Services. It didn’t take long to notice that the RIA Services template only allows for the WAP style projects. So I started to wonder how to go about adding RIA to existing web sites. I put together a quick example of how to structure a solution to enable RIA on a stand ASP.Net Web Site. The projects look this:

 image

  • RegularWebSite: Obviously this is the regular non-compiled site, created using the ASP.Net Web Site template.
  • ExampleRIAServicesApplication: This is a project created using Silverlight Navigation Application template.
  • ExampleRIAServicesLibrary: A Silverlight class library project that was created using the WCF RIA Services Class Library project template. The template also created the next project automatically.
  • ExampleRIAServicesLibrary.Web: A .Net class library project that was created using the WCF RIA Services Class Library project template.

 

Once these projects were created I started setting up the Domain Services that will be hosted on the ASP.Net site. To do this I first added the following references to the ExampleRIAServicesLibrary.Web:

image

I then added a LinqToSql model to the project and created a Domain Service to expose the entities in the model. (To keep this post focused, I will not be discussing how to create the domain services. There are plenty of great resources on how to create these services, write custom queries, enable authentication and so on. This article is meant only to explain how to use RIA Services with a non-compiled ASP.Net site.) Once I had these services built (or at least started), I built the ExampleRIAServiceLibrary.Web project and verified that the code was generated in the ExampleRIAServiceLibrary project. If the code is generated, then the RIA Services link is functioning properly and you can move on to wiring this library projects to the application projects.

image

Note: If the code is not generated verify that the Silverlight class library is linked to the .Net library via the .Net RIA Services link project property.

image

 

First I added a reference to the ExampleRIAServiceLibrary project in the main Silverlight application:

image

Then I added a reference to the ExampleRIAServiceLibrary.Web project in the RegularWebSite project:

image

The final step to link all of the projects together is to link the ExampleRIAServicesApplication Silverlight application to the web site:

image

Now that all of the projects are linked properly, I built the solution to verify that all of the files were generated and\or copied to the appropriate locations and no errors where reported. Everything built properly so we are ready to published right? Well, actually not yet. There are a few web.config changes that need to be made to allow the Domain Services to function properly. All of the changes that need to be made should be found in the App.Config file of the ExampleRIAServiceLibrary.Web and can be copied directly into the RegularWebSite web.config. First make sure that the necessary connection strings are copied over so the Domain Services can access the data store. The two RIA Services specific settings are as follows:

Under system.web->httpModules  add the following entry: 

<add name="DomainServiceModule" 
                 type="System.Web.Ria.Services.DomainServiceHttpModule, System.Web.Ria, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/> 
    

 

You also need a system.serviceModel section that contains the following entry:

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

If your site already contains a system.serviceModel section, then simply add (or verify) the serviceHostingEnvironment settings.


After the configuration changes are made you are ready to start building and debugging (unless you right perfect code of course) you new RIA Services enable Silverlight Application. Keep in mind while this articles describes this process using all new projects, the principals are described will work on existing projects and sites.

Now go out there, grab the latest RIA Services bits (in case you haven’t heard, the beta version was released at PDC this week!) and have fun coding! And as always I appreciate and encourage your feedback, comments and questions. Thanks!





Comments are closed.
Showing 5 Comments
Avatar  Ian T. Lackey 7 years ago

Thanks everyone for your feedback! Yes it is much easier to use the WAP template for new projects, in general. However there are times when this cannot happen, so it is good to see there are options.

Avatar  Rob Brown 7 years ago

Thanks very much for your post. Helped me get RIA services working with an existing .NET site a few months ago, although we have had to change it now to a web application project in order for access to existing libraries in the site.

Avatar  vxan 7 years ago

Hi many thanks for this great information, I am wondering if you have made any tests with Silverlight 4?

Avatar  Shreedhar 7 years ago

Great tip. I was stuck around the same problem. I wonder why they do not support RIA services link to regular web site projects. Thanks anyway for a great post.

Avatar  Anonymous 8 years ago

Excellently written article, if all bloggers offered the same content as you, the internet would be a much better place. Please keep it up! Cheers.