Silverlight deployment: deploying to multiple environments

Today I got an interesting question, namely they were using services in their silverlight application, but each time they needed to deploy they unzipped the .xap file to change the ServiceReferences.ClientConfig configuration to use their production server. of course this meant re-zipping back to .xap, and possible mistakes during deployment. So on several occasions a QA .xap was deployed in production.

So how can you avoid this? Well, I think the best way is to move the changing configuration to outside the .xap file. For example we can deploy a simple file to the web server where the silverlight application is deployed and add the server address in it:

<servers>

  <server type="movieServer"

          uri="http://PRODUCTION_SERVER/MovieService.svc"

  />

</servers>

 

For each deployment environment you would keep a separate file, making sure that future deployments cannot overwrite it by accident (for example by setting ACL’s on the file).

Next, when the silverlight application starts we download this file from the server using the WebClient class:

Dim WithEvents wc As New WebClient

 

Private Sub GetTheServers()

  wc.DownloadStringAsync(New Uri("servers.xml", UriKind.Relative))

End Sub

 

Once we receive the DownloadStringCompleted event we parse the server’s address out of the received xml:

Dim movieServerAddress As String

Private Sub wc_DownloadStringCompleted(ByVal sender As Object,

             ByVal e As System.Net.DownloadStringCompletedEventArgs)

             Handles wc.DownloadStringCompleted

  Dim doc = XDocument.Parse(e.Result)

  Dim movieServerQuery = From server In doc...<server> _

                         Where server.@type = "movieServer" _

                         Select server.@uri

 

  movieServerAddress = movieServerQuery.Single()

End Sub

 

When we need to call the service (for example a WCF service) we simply use the stored movieServerAddress:

Private Sub LoadTheMovies(ByVal sender As System.Object,

                          ByVal e As System.Windows.RoutedEventArgs)

  proxy = New MovieServiceReference.MovieServiceClient( _

            New BasicHttpBinding(), 
            New EndpointAddress(movieServerAddress))

  proxy.GetListOfMoviesAsync()

End Sub

 

You could avoid downloading the servers.xml file multiple times by storing it in Isolated storage. So the first time isolated storage wouldn’t have this information yet, so you would call GetTheServers. Then you could parse its contents and store the information in isolated storage. Next time you would find it in isolated storage, saving the round-trip to download it…


February 9. 2010 09:09 AM

colon cleaner

Victory always starts in the head. It's a state of mind. It then spreads with such radiance and such affirmations that destiny can do nothing but obey.

colon cleaner

February 22. 2010 05:33 AM

Photo Collage

Hi. this is kind of an "unconventional" question , but have other visitors asked you how get the menu bar to look like you've got it? I also have a blog and am really looking to alter around the theme, however am scared to death to mess with it for fear of the search engines punishing me. I am very new to all of this ...so i am just not positive exactly how to try to to it all yet. I'll just keep working on it one day at a time.

Photo Collage

February 23. 2010 11:56 PM

Myspace - Make Money Online

Hey - nice blog, just looking around some blogs, seems a pretty nice platform you are using. I'm currently using Wordpress for a few of my sites but looking to change one of them over to a platform similar to yours as a trial run. Anything in particular you would recommend about it?

Myspace - Make Money Online

February 28. 2010 06:24 PM

Social Marketing

Nice to be visiting your blog again, it has been months for me. Well this article that i've been waited for so long. I need this article to complete my assignment in the college, and it has same topic with your article. Thanks, great share.

Social Marketing

Add comment

  Country flag

biuquote
  • Comment
  • Preview
Loading

Download the U2U brochure

Download Brochure

Receive the U2U Newsletter. Submit your email address:
 
 


 


Search

rss  RSS

Archive