Click here to Skip to main content
15,794,475 members
Articles / Programming Languages / ASM

Dynamically send WCF endpoint in Silverlight

Rate me:
Please Sign up or sign in to vote.
5.00/5 (1 vote)
17 May 2011CPOL 10.7K   1   3
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);


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

Written By
Software Developer (Senior) Paddedwall Software
United States United States
I've been paid as a programmer since 1982 with experience in Pascal, and C++ (both self-taught), and began writing Windows programs in 1991 using Visual C++ and MFC. In the 2nd half of 2007, I started writing C# Windows Forms and ASP.Net applications, and have since done WPF, Silverlight, WCF, web services, and Windows services.

My weakest point is that my moments of clarity are too brief to hold a meaningful conversation that requires more than 30 seconds to complete. Thankfully, grunts of agreement are all that is required to conduct most discussions without committing to any particular belief system.

Comments and Discussions

GeneralRe: By copy paste, I meant you have to have two endpoint definit... Pin
Omar Al Zabir17-May-11 8:22
Omar Al Zabir17-May-11 8:22 
GeneralGood solution, but it makes it work for one specific product... Pin
Omar Al Zabir17-May-11 5:17
Omar Al Zabir17-May-11 5:17 
GeneralRe: Well, we only have one production end point. The point is th... Pin
#realJSOP17-May-11 5:22
mve#realJSOP17-May-11 5:22 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.