A Guide to Deploying RIA Services Solutions

[WCF RIA Services Version 1 Service Pack 2 is compatible with either .NET framework 4 or .NET Framework 4.5, and with either Silverlight 4 or Silverlight 5.]

This topic describes the tasks to perform when deploying your WCF RIA Services application to a Web server. Deployment to a Web server requires that the server has the .NET Framework 4 and either Internet Information Server (IIS) 6 or 7 installed to host the application. RIA Services must also be available on the Web server, but it may not be possible to simply install it there and so other deployment options are discussed. The ASP.NET Web application must be correctly configured for a successful deployment and the settings required in the Web.config are outlined. Finally, the publishing procedure is described.

Issues that can arise when deploying a RIA Services application and recommendations on how to deal with them are described in the Troubleshooting the Deployment of a RIA Services Solution topic.

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.

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 and Installing IIS 6.0.

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 Deployment

    When 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

    • System.ServiceModel.DomainServices.Server.dll

    • System.ServiceModel.DomainServices.Hosting.dll

    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 Deployment

    Instead 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.

Warning

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=4.0.0.0, 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=4.0.0.0, 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.

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.

Deploy the RIA Application

Publish the Web Application on IIS

  1. Open your RIA Services 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.

  2. Select the Web project in the Solution Explorer, right-click and select Publish.

  3. 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.

  4. Check the Mark as IIS application on destination and Leave extra files on destination (do not delete) boxes.

  5. Click on the Publish button.

  6. 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.

  7. 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.

Warning

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.

Specify the Authentication Mode in IIS Manager

  1. Select you Web application in the Connections pane of IIS Manager.

  2. Double-click on Authentication in the IIS group in the Features View.

  3. 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.

Warning

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.

If you are having issues getting the test page to display properly, consult the Troubleshooting the Deployment of a RIA Services Solution topic for assistance.