Click here to Skip to main content
Click here to Skip to main content

Dynamically send WCF endpoint in Silverlight

By , 17 May 2011
 
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)

About the Author

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

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
Hint: For improved responsiveness ensure Javascript is enabled and choose 'Normal' from the Layout dropdown and hit 'Update'.
You must Sign In to use this message board.
Search this forum  
    Spacing  Noise  Layout  Per page   
GeneralRe: By copy paste, I meant you have to have two endpoint definit...memberOmar Al Zabir17 May '11 - 7:22 
GeneralGood solution, but it makes it work for one specific product...memberOmar Al Zabir17 May '11 - 4:17 
Good solution, but it makes it work for one specific production endpoint. And you end up copying and pasting all the endpoints twice, one for localhost and one for production.
GeneralRe: Well, we only have one production end point. The point is th...mvpJohn Simmons / outlaw programmer17 May '11 - 4:22 

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

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