views:

18

answers:

2

We've just added a dedicated test server for our Silverlight applications. We are deploying full copies of all our apps and services onto the test server. The issue we have is that we need to manually update ServiceReference.ClientConfig when we deploy, to point to the appropriate server (ie. test or live).

I'm sure this is a common issue. What is the "best practice" solution?

+1  A: 

I would programmatically change the endpoint's hostname inside your silverlight application depending on a particular parameter passed from the host page to the SL app (of course this means you will have to host your application on a different page when you deploy on the test server -or you can edit the host page "on the fly" as part of your deploy script).

For ex.: on the test page:

 <param name="initParams" value="testServer=myhost.com"/>

Then in the Silverlight app you read the testServer parameter (you receive the initParams hashtable in the Application_Startup event) and programmatically set the hostname to what you received. You will need some kind of centralized factory for the remote proxy otherwise you will have to replace the hostname in several different places.

Also, I would only do this #if DEBUG (or even better define another compilation constant that will be removed before the actual deploy) so there's no risk that this will be used for any malicious goal.

Francesco De Vittori
I do something similar, but I've found i like the results better if you host the app in a ASP.NET page and write the initParams in dynamically from the host's web.config file. It allows you to easily install in different locations by installing different config files on the host page.
Stephan
+1  A: 

I usually create a Configuration folder in my SL web project, containing a ServiceReferences.ClientConfig for each location I intend to publish the application to (ServiceReferences.ClientConfig.dev, ServiceReferences.ClientConfig.test, ServiceReferences.ClientConfig.prod).

Then I create a solution configuration for each environment (dev, test, prod) and set the SL app build event to:

xcopy /R /Y $(ProjectDir)Configuration\ServiceReferences.ClientConfig.$(ConfigurationName) $(ProjectDir)ServiceReferences.ClientConfig

Before publishing, I just need to select the configuration, build and publish

vc 74