locked
Changing the WCF service URL after compilation RRS feed

  • Question

  • We have a silverlight application hosted by an ASP.NET application where the silverlight app gets its data by calling a WCF service.  The WCF service is in a different ASP.NET application than the Silverlight application (so that it can be deployed and managed separately).

    Maybe I'm missing something obvious here but is there some way I can access the ServiceReference.config data after I compile in order to change the URL of the WCF service?  Our intention is to sell the application to clients who would host it on their own domains, so we wouldn't know the service URL at compile time (and certainly wouldn't want to have to compile it separately for everyone who buys it!).

    I can't find anyplace where this service URL is exposed in text in the precompiled application.  Is there a way to use the web.config of the ASP.NET application to pass in the service URL to Silverlight using InitParams instead of using the value from the ServiceReference.config file, so that we could put the service URL in the web.config instead? 

    Thanks in advance.

    Wednesday, February 18, 2009 5:17 PM

Answers

  •  Sometimes I think writing these messages helps me brainstorm... I figured it out.

    Just using an overload of the Client constructor that passes the URL of the service works fine.  So I can put this URL in my ASP.NET web.config, pass it down to Silverlight, and all is hunky dory.

    I now return you to our normal slew of questions...

    Wednesday, February 18, 2009 6:05 PM
  • After compilation, your silverlight assembly and ServiceReferences.ClientConfig and other related file are ziped in .xap file. You can unzip it and modify  ServiceReferences.ClientConfig

    Thursday, February 19, 2009 11:59 PM

All replies

  •  Sometimes I think writing these messages helps me brainstorm... I figured it out.

    Just using an overload of the Client constructor that passes the URL of the service works fine.  So I can put this URL in my ASP.NET web.config, pass it down to Silverlight, and all is hunky dory.

    I now return you to our normal slew of questions...

    Wednesday, February 18, 2009 6:05 PM
  •  Hey there,

    You can also calculate the relative URI automatically from your Silverlight app... see this post for more info and demo: http://blog.webjak.net/2008/10/21/get-a-relative-uri-to-your-webwcf-service-in-silverlight/

    Cheers,

    Jordan.

    Wednesday, February 18, 2009 7:20 PM
  •  Thanks for the link, unfortunately that isn't going to help in this scenario because I can't guarantee that the relative link will always be the same.  The service may or may not even be on the same domain...

    Wednesday, February 18, 2009 10:24 PM
  • After compilation, your silverlight assembly and ServiceReferences.ClientConfig and other related file are ziped in .xap file. You can unzip it and modify  ServiceReferences.ClientConfig

    Thursday, February 19, 2009 11:59 PM