Ok, after much searching around the net I was able to code the following solution by aggregating the different pieces of information I found.
First, Silverlight 4 (like SL3) use a different mechanism for creating the silverlight control in the web page on the client. It uses the < object > tag.
To pass initialization parameters to a silverlight application you just need to add
<param name="initParams" value="key1=value1,key2=value2" />
to the page.aspx file (from the web project) under the object tag and the SL app will receive those 2 parameters at startup.
For example, using the default aspx page generated from VS2010:
<object data="data:application/x-silverlight-2," type="application/x-silverlight-2" width="100%" height="100%">
<param name="source" value="ClientBin/MyApp.xap"/>
<param name="onError" value="onSilverlightError" />
<param name="background" value="white" />
<param name="minRuntimeVersion" value="4.0.50401.0" />
<param name="autoUpgrade" value="true" />
<param name="initParams" value="key1=value1,key2=value2" />
<a href="http://go.microsoft.com/fwlink/?LinkID=149156&v=4.0.50401.0" style="text-decoration:none">
<img src="http://go.microsoft.com/fwlink/?LinkId=161376" alt="Get Microsoft Silverlight" style="border-style:none"/>
</a>
</object>
To access the parameters in the SL app, you just have to code the following in the App.xaml.cs file:
private void Application_Startup(object sender, StartupEventArgs e)
{
var builder = new StringBuilder ();
foreach (String key in e.InitParams.Keys)
builder.AppendFormat ("from InitParams: {0} = {1}",
key, e.InitParams[key]).AppendLine ();
HtmlPage.Window.Alert (builder.ToString ());
// Other code...
}
For now, this only allows static values for the parameters.
To have dynamic values you just have to change the initParam line to:
<param name="initParams" value="<%= string.Format("WCFReferenceURL={0}", ConfigurationManager.AppSettings["WCFReferenceURL"])%>" />
to get the values from the configuration file on the web server. ;)
I hope this helps some poor soul out there!