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:
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:
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.
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.
First I added a reference to the ExampleRIAServiceLibrary project in the main Silverlight application:
Then I added a reference to the ExampleRIAServiceLibrary.Web project in the RegularWebSite project:
The final step to link all of the projects together is to link the ExampleRIAServicesApplication Silverlight application to the web site:
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" ...