views:

112

answers:

2

I need to deploy a silverlight 4 soltution where it consumes data from a WCF service. The challenge is this will be a production install and so I have no way of controlling the server name of the service and the silver light app will not be installed on the same server as the WCF.

Starting down this path here is what I have come up with thus far:

I will have to pass the server name of teh WCF to my silverligth app via initParams.

within the aspx file I have

<param name="initparams" value="servicepoint=http://myservice" />

then within the app.xaml.cs I call the param:

private void Application_Startup(object sender, StartupEventArgs e)
    {
        this.RootVisual = new MainPage(e.InitParams); //pass parameter from html direclty to main page

    }

I called this within app startup so the paramater would be in scope of the entire app.

Now within main page I assign this param to a variable

dswconnection = initParams["servicepoint"];

and then whenever I query the service I set the address to override what is defaulted within the service refernece.config file

QueryClient selAct = new QueryClient("BasicHttpBinding_IQuery");
            selAct.Endpoint.Address = new System.ServiceModel.EndpointAddress(dswconnection);

My question is.... is this the best approach or is there another way to dynamically identify the server name of a service when you don't know what that server name could be. This the key point I can't use some of the features to detect host name or address within channelfactory as the silverlight app will reside on a different host than the WCF.

Right now the value that is passed to initparams is stored in a config file that is read by javascript and then assigend as the value. In my code here I hard coded it for brevity.

Thanks for any suggestions.

A: 

After some more research it appears in instances where the sl app is to be installed on separate servers or if hte need is to have it point to different WCF endpoints the above approach worked the best for this project. We ended up storing the full qualified server name for the endpoin in a web.config file with other connection strings. Then passed this value to the init params using JSON. Silverlightwas then able at intializtion to pick up the new server name and point the SL app towards the new service.

randyc
A: 

what i did is to open the xap file with zip, then update end point the servicereference.clientconfig file manually, then zip back.

fresky
Thanks Fresky, the challenge we faced here was this app needed to be deployed to multiple sites. Instead of manually editing each xap file at installation we wanted to go wtih something more along the lines of a configuration file where the servername could be configured at installation vs. manually touching each xap file after isntall.
randyc