Geeks With Blogs
Braulio Díez Botella blog

SL Calling same domain WCF located service zero configuration

Nice stuff… in my app’s I use to have a config.xml file associated to my Silverlight application, it included an entry to specify the root url to access the WCF services that I need to call in my app.

It was a pain on the neck swapping between localhost and server mode (remember always to set the right config. Blah blah…), googling a bit I have found nice solution… why do you need to host that root url in a file? You already can grab it from the navigator that is browsing your page !!! this function works quite well:


    public string GetServiceProxyURL()


            string serviceBase = "";



            if (Application.Current.Host.Source.Host.ToUpper() == "LOCALHOST")


                    serviceBase = string.Format("{0}://{1}:{2}",







                    // include the appname in the path

                    string url = System.Windows.Browser.HtmlPage.Document.DocumentUri.AbsolutePath;

                    string[] path = url.Split("/".ToCharArray());

                    string appname = path[1];


                    serviceBase = string.Format("{0}://{1}",


                        Application.Current.Host.Source.Host, appname);



      //Here you can add any subfolder if needede

            //serviceBase += "/WsCommunicator/";


            return serviceBase;                       



Posted on Friday, July 10, 2009 10:59 PM | Back to top

Comments on this post: SL Calling same domain WCF located service zero configuration

No comments posted yet.
Your comment:
 (will show your gravatar)

Copyright © Braulio Díez Botella | Powered by: