ClickOnce and WCF

I've been concerned about the relationship between ClickOnce and WCF. Lot of buzz has been generated regarding partial-trust scenario not being supported for WCF v1. I see this as something desirable, but it is not the end of the world :)

I've written a Smart Client application that leverage WCF.  I wanted to deploy it so I choose ClickOnce. ClickOnce supports installing prerequisites as part of the whole process, so I downloaded WinFx and include it as part of the installation. If you are insterested in how to do this, keep reading.

WCF is part of
the WinFX Runtime Components, which is currently in Beta 2 (Feb CTP). The installation of this runtime requires
Admin privileges
and the size of the Redistributable package is 45.3 MB.
These are the alternatives to distribute it on client desktops:

  • Install
    WinFx manually on each desktop :)
  • Use SMS
    to distribute WinFx
  • Include
    WinFx as part of the prerequisites of the ClickOnce application
  • Distrubute
    an MSI which includes WinFx

I was interested in the 3rd option, so let's analyze it further

Include WinFx as part of the prerequisites of the
ClickOnce application

ClickOnce has a feature that allows including the
prerequisites of the application to be deployed. When the application is published
it creates a setup bootstraper that will download and install all the
prerequisites (if they were not installed yet) before the ClickOnce application
is executed. This way the deployment will be more controlled as it will be a
single package.

The user executing the setup bootstraper must have
Admin
privileges. If the user logged does not have Admin privileges, an
option would
be to execute Internet Explorer with “Run As…” and login with a local
administrator account. This will at least install the prerequisites and
also the application in the Administrator profile. Later you would need
to open a new IE instance and launch the app again from the currently
logged user.

The following sequence illustrates the install of

prerequisites (.Net Framework 2.0 and WinFx Beta 2)

<!--[if !vml]-->clickonce1

Figure 1. Prerequisites of the
application listed in the Publish ClickOnce html file

clickonce2

Figure 2. Pressing
Install will launch the bootstrapper that detects the uninstalled
prerequisites: Net Framework 2.0 and WinFx Runtime Components Beta 2

clickonce3 
Figure 3. The setup downloads the prerequisites from a specific location

clickonce4



<!--[if !vml]--><!--[endif]-->

Figure 4. After
downloading, the setup will install the WinFx Runtime Components

Using WCF on your application requires more
CAS permissions (FullTrust)

In many real scenarios, developers need their applications
to run as a Partial Trust Application, but need more permissions. For example,
you may need to use a SQL Client. To solve this kind of problems, ClickOnce introduces a feature called Permission
Elevation
, which allows an application without enough permissions to
request them to the user. If the user accepts, then the needed permissions are
granted and the application can run normally. This could goes up till
FullTrust which is the requirement for WCF. Besides, in scenarios in which users should not make these kinds of
decisions, a practical solution is offered: system administrators can sign the
application manifests or set a deployment policy that specifies that a
publisher is a trusted source. This way, permissions will automatically be
granted before the application loads.

clickonce5

Figure 5. Installing the application and permission elevation

Creating the prerequisites

WinFx does not come as a prerequisite in the
Visual Studio 2005 Publish tab. However, we can create our own
prerequisite with any MSI or EXE installation.

The process to do this is:

  1. Create a new folder called "WinFx" here %Program Files%\Microsoft Visual Studio 8\SDK\v2.0\BootStrapper\Packages
  2. Use the Bootstrapper Manifest Generator to create the manifest for WinFx. I've created it already for WinFx.
  3. Copy the manifest to %Program Files%\Microsoft Visual Studio 8\SDK\v2.0\BootStrapper\Packages\WinFx
  4. Copy the WinFx Runtime Components redistributable to the same folder
  5. Restart Visual Studio 2005

More resources

Published: April 06 2006

blog comments powered by Disqus