Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles / Languages / ASM

Dynamically send WCF endpoint in Silverlight

5.00/5 (1 vote)
17 May 2011CPOL 11.6K  
This is how I do it (we determine the host and select the appropriate endpoint).// these are the endpoints define in the webconfig filestring LocalHostEndpointName = LocalHost_Endpoint;string ProductionEndpointName = Production_Endpoint;string CurrentEndpoint = ;//...
This is how I do it (we determine the host and select the appropriate endpoint).

C#
// these are the endpoints define in the webconfig file
string LocalHostEndpointName  = "LocalHost_Endpoint";
string ProductionEndpointName = "Production_Endpoint";
string CurrentEndpoint        = "";

// this is the code we use to determine the correct endpoint
string host = Application.Current.Host.Source.Host.ToLower();
host = (string.IsNullOrEmpty(host)) ? "localhost" : host;

switch (host)
{
    case "localhost" : CurrentEndpoint = LocalHostEndpointName;   break;
    default          : CurrentEndpoint = ProductionEndpointName;  break;
}

webService = new Svc.MyServiceClient(CurrentEndpoint);

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)