65.9K
CodeProject is changing. Read more.
Home

Dynamically send WCF endpoint in Silverlight

starIconstarIconstarIconstarIconstarIcon

5.00/5 (1 vote)

May 17, 2011

CPOL
viewsIcon

11610

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).
// 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);