Introductions. My name is Brad Severtson. I joined the WCF RIA Services team last fall and have worked on the documentation for the upcoming v1 SP1 release. I am a senior programming writer and have worked mainly on WCF and Silverlight technologies. This deployment guide is part of that RIA SP1 doc set. I am releasing the basic parts of this topic early here due to the continued request for guidance on deployment. (I have had to delete some of the links to other SP1 topics, or redirected them to the related current documents, as they will not work until they are published.)
This topic has attempted to take all of the existing guidance that has been published on the blogs and provided in videos by the product team (and in particular the Saurabh Pant video on Silverlight TV: http://johnpapa.net/silverlight/sltv51/), several of whose members have also reviewed it as well, and put them into a single procedure that provides a check list of things you should do when deploying a RIA application. I have worked through it myself more than a few times, of course, mostly with success. There are machines that just seem to have too much *history* or some sort gremlins to configure correctly. I have had gook luck with freshly configured test machines, not as good with machines I have been using for years. So here it is:
A Guide to Deploying RIA Services Solutions
An outline of the issues that can arise when deploying a RIA Services application and some recommendations on how to deal with them are described in the Troubleshooting a RIA Services Solution (http://go.microsoft.com/fwlink/?LinkId=211605) topic. This also provides some useful conceptual background (in the discussion on excption flow) on the application layers you are dealing with when deploying a RIA Services application.
Confirm That the .NET Framework 4 is Installed on the Web Server
The .NET Framework 4 must be installed on the Web server for a RIA Services application to work. For more information, see Installing the .NET Framework (http://go.microsoft.com/fwlink/?LinkID=184895).
Confirm that IIS is installed on the Web Server
The Internet Information Server (IIS) 6 or 7 must be installed on the Web server for a RIA Services application to work. For more information, see IIS 7 Installation and Deployment (http://go.microsoft.com/fwlink/?LinkId=210171) and Installing IIS 6.0 (http://www.microsoft.com/technet/prodtechnol/WindowsServer2003/Library/IIS/750d3137-462c-491d-b6c7-5f370d7f26cd.mspx?mfr=true).
Install RIA Services on the Web Server
The RIA Services assemblies must be available on the Web server. It is recommended that RIA Services be installed on the Web server that will host your application. If this is not an option, due to lack of permissions or some other issue, you can also make them available on the Web server by either including them in the bin folder of your project when it is published or by installing them in the global assembly cache (GAC).
Bin DeploymentWhen deploying your application, one option is to include the RIA Services assemblies in the bin folder of your project. To do this with in Visual Studio, you must select each of the Web project assembly references in the Solution Explorer that must be included and set the Copy Local property to True in the Properties window. The two assemblies that must always be included are
Setting these property values to True results in the assemblies getting copied to the bin folder the next time you build the solution. When the assemblies are copied to the bin folder, they will be copied to the Web server when you publish the site.
If you are using Entity Framework to access a database, then you will also need to add a reference to the System.ServiceModel.DomainServices.EntityFramework.dll assembly.
If you are using LINQ to SQL to access data, then you will need to add a reference to the Microsoft.ServiceModel.DomainServices.LinqToSql.dll assembly.
GAC DeploymentInstead of copying the RIA Services assemblies in the Bin folder of every project that uses them, you can install the assemblies in the GAC. Any assemblies in the GAC are available to every application on the server. This approach is easier to maintain because an assembly only needs to be updated in the GAC instead of every Bin folder.To install the RIA Services assemblies in the GAC on a Web server, run the following command: msiexec /i RiaServices.msi SERVER=TRUE
Configure the Web Server
The deployment of a RIA Services application on a Web server requires that its Web.config files contain properly configured elements and attributes. The Web.config file manages the configuration of the ASP.NET application and is created automatically when you choose to host a Silverlight application with an ASP.NET Web project on the New Silverlight Application wizard. This Web.config file initially only specifies that the target framework is .NET Framework 4.0 in the <compilation> element. The actual values needed for deployment are set in the Web.config file by default when you add a service domain to the Web project of a RIA Services application using the Add New Domain Service Class wizard.
There are several sections of the Web.config file that are critical to deployment. These are the sections that configure the ASP.NET hosting mode, IIS, and the authentication mode. This section discusses the values of the configuration elements in these sections needed to deploy a RIA Services application. The wizard sets these values by default, but they could be altered by various procedures before attempting to publish. So it is useful to know the correct values and to confirm that they are set as expected. The section also describes several procedures that use the Internet Information Service (IIS) Wizard to insure that IIS is configured consistently with the values specified in the Web.config file.
RIA Services domain services are Windows Communication Foundation (WCF) services and when hosted with ASP.NET need to be hosted in ASP.NET Compatibility Mode. This requirement cannot be set in code and must be specified in the Web.config file. The ASP.NET Compatibility Mode is enabled by setting the aspNetCompatibilityEnabled property to true in the <ServiceHostingEnvironment>element of the <system.serviceModel> section:
<system.serviceModel> <serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" /></system.serviceModel>
The true value is set by default. The compatibility mode enables a domain WCF service to use all of the features of the ASP.NET Web application platform. Setting the multipleSiteBindingsEnabled attribute to true enables multiple IIS bindings per site for a service with the HTTP protocol. For more information about the consequences of enabling these features, see WCF Services and ASP.NET (http://go.microsoft.com/fwlink/?LinkId=210198).
Caution: WCF services have many hosting options other than IIS. They can be self-hosted in a managed application, hosted in a managed Windows Service or by the Windows Process Activation Service (WAS). So WCF services must opt into ASP.NET Compatibility Mode. But RIA Services domain services can only be IIS hosted and so are restricted to the use of the HTTP transport.
The Add New Domain Service Class wizard adds an <add> element of the <httpModules> element within the system.web section that is required by IIS 6. Confirm that the .NET Framework 4.0 has been targeted in the <compilation> element of this section and that the domain service module has been added with the following values:
<system.web> <httpModules> <add name="DomainServiceModule" type="System.ServiceModel.DomainServices.Hosting.DomainServiceHttpModule, System.ServiceModel.DomainServices.Hosting, Version=220.127.116.11, Culture=neutral, PublicKeyToken=31BF3856AD364E35" /> </httpModules> <compilation targetFramework="4.0" /></system.web>
The Add New Domain Service Class wizard adds a <modules> element in the <system.webserver> section that is required by IIS 7. Confirm that it contains the following values:
<system.webServer> <modules runAllManagedModulesForAllRequests="true"> <add name="DomainServiceModule" preCondition="managedHandler" type="System.ServiceModel.DomainServices.Hosting.DomainServiceHttpModule, System.ServiceModel.DomainServices.Hosting, Version=18.104.22.168, Culture=neutral, PublicKeyToken=31BF3856AD364E35" /> </modules></system.webServer>
Tip: You only need to retain the configuration elements needed for the version of IIS that is being used to deploy the application. If you are deploying with IIS7, for example, the elements configuring IIS6 should be removed. But no harm is done if both sets of hosting elements are retained. (But it has been reported that removing the IIS 6 configuration elements can break the developer "Cassini" environment.)
Only one authentication schema can be enabled when working with a RIA Services solution. The <authentication> element in the Web.config file configures the ASP.NET authentication scheme for an ASP.NET application. The authentication scheme determines how to identify users who want to view the ASP.NET application. The mode attribute specifies the authentication scheme. Check the <authentication> element of your Web.config file and other configuration files in the hierarchy to ensure that more than one schema (Windows, Forms, Passport, None) is not enabled. The section is not explicitly created by default when creating a domain service for a RIA Services application. The default value used when the element is not explicitly specified is <authentication mode = “Windows”>. After the Web application is published, we need to check that IIS has only Windows authentication enabled (if you are using that option), and this procedure is described below.
For more information on Web.config settings, see ASP.NET Configuration (http://go.microsoft.com/fwlink/?LinkId=210201).
Deploy the RIA Application
Publish the Web Application on IIS
Open your application in Visual Studio 2010. You need administrator privileges to publish, so be sure to right-click on Visual Studio 2010 in the Start menu and select Run as Administrator when you open the application.
Select the Web project in the Solution Explorer, right-click and select Publish.
Choose Web Deploy as the Publish method, specify localhost (if publishing locally, or the remote server name if publishing remotely) as the Service URL, and specify Default Web Site (again if the server is local) as the Site in the Site/application box and the name of you application as the application in the box. For example, to publish a RIA Services application named RIAApp1 locally, you would enter Default Web Site/RIAApp1.
Check the Mark as IIS application on destination and Leave extra files on destination (do not delete) boxes. Click on the Publish button.
Open the Internet Information Services (IIS) Manager, navigate to the Web application just published in the Default Web Site list contained in the Connections pane and select the Content View tab near the bottom of the Window.
To open a test page for your site, select the ASP.NET Server Page, right-click and select Browse.
Tip: If you have bin-deployed the assemblies needed by RIA Services applications, then they can be found in the bin file folder in the IIS Manager. This folder will also contain the assembly for the Web application.
Caution: If the application fails to appear on the test page, then there are issues with either ASP.NET or Silverlight. For additional information on Silverlight deployment, see Deployment and Localization (http://go.microsoft.com/fwlink/?LinkId=210217).
Specify the Authentication Mode in IIS Manager
Select you Web application in the Connections pane of IIS Manager.
Double-click on Authentication in the IIS group in the Features View.
Make sure that Windows Authentication (or whatever mode of authentication you have chosen to employ) is enabled. IIS only supports Anonymous Authentication by default, so this procedure is typically required to change this. ASP.NET allows multiple modes of authentication to be enabled and the IIS Manager allows such settings. RIA Services allows Forms Authentication to be used in adjunct with Anonymous Authentication (so people can access the login page), but it only allows Windows Authentication by itself. Right-click on any of the Names and select Enable or Disable as required to limit the authentication enabled to one mode.
Caution: If you do not see the Windows Authentication or other modes besides Anonymous Authentication, then you need to install missing components of IIS. For more information on these prodedures, see IIS 7 Installation and Deployment (http://go.microsoft.com/fwlink/?LinkId=210171).
I hope these instructions help get the deployment job for most of you.
Another common problem is that WCF RIA Services does not work when a Web Deployment Package is being used. The reason for that is currenlty being investigated.
I always deploy ria services enable apps with web deployment packages without any problems.
@Ernesto Thanks for the data point, I have seen many examples of it not working with a Web Deployment Package but hasn't seen one where it worked. One of the theories is that the problem is in the precompiledapp.config. Is there anything different that you are doing such as deleting the precompiledapp.config? Are you using a WCF RIA Services Class Library? Is WCF RIA Services installed on the server or do you have the dlls in the bin folder?
You mention that RIA Services can only be hosted in IIS but Visual Studio LightSwitch that uses RIA Services internally can be deployed in a 2-tier architecture using ClickOnce and run on the desktop without the need for IIS. I am currently trying to use RIA Services in the same setup and would appreciate any information on this subject.