Click here to Skip to main content
12,293,601 members (65,632 online)
Click here to Skip to main content
Add your own
alternative version

Tagged as

Stats

4.7K views
1 bookmarked
Posted

Dynamically send WCF endpoint in Silverlight

, 17 May 2011 CPOL
Rate this:
Please Sign up or sign in to vote.
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);

License

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

Share

About the Author

John Simmons / outlaw programmer
Software Developer (Senior)
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.

You may also be interested in...

Comments and Discussions

 
GeneralRe: By copy paste, I meant you have to have two endpoint definit... Pin
Omar Al Zabir17-May-11 7:22
memberOmar Al Zabir17-May-11 7:22 
GeneralGood solution, but it makes it work for one specific product... Pin
Omar Al Zabir17-May-11 4:17
memberOmar Al Zabir17-May-11 4:17 
GeneralRe: Well, we only have one production end point. The point is th... Pin
John Simmons / outlaw programmer17-May-11 4:22
mvpJohn Simmons / outlaw programmer17-May-11 4: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.

| Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.160525.2 | Last Updated 17 May 2011
Article Copyright 2011 by John Simmons / outlaw programmer
Everything else Copyright © CodeProject, 1999-2016
Layout: fixed | fluid