Click here to Skip to main content
Click here to Skip to main content
Technical Blog

Tagged as

Windows Azure, TDS, WCF, Silverlight and a few problems on the way Part IV - The Silverlight Project

, 27 May 2009 CPOL
Rate this:
Please Sign up or sign in to vote.
Hosting a Silverlight Application in an Azure Application

Introduction

After a short sojourn with the Visual Studio 2010 Beta, I'm back with the next part. Pop quiz – can you run Visual Studio Team Foundation and Visual Studio Professional without Team Suite? Well some wit told a client you could not – so I spent some of the Bank Holiday proving otherwise – Another article there on setting it up, but in general it was incredibly easy for a server app! Anyway I digress back to the subject at hand – hosting a Silverlight Application in an Azure Application.

This was the part that gave me the most gotchas.

Adding a Silverlight Project to the Azure Solution

Right click on the Solution and click on the ‘Add New Project’.

image

Select The ‘Silverlight Application’ – Give your Silverlight Application a name and then click on ‘OK’.

When you hit the ‘OK’ button, you will be presented with a new window to create the Web Application that will host the Silverlight App. Well, we already have a web app. It is the WebRole – for this reason, we select the third option – ‘Link this Silverlight control into an existing Web Site’, if it has not already been selected.

image

Of the three options at the bottom ensure the first is selected, we will raid this page for some code. Deselect the Make it the start page and select the Enable Silverlight debugging option.

Now there is a known issue in the WCF Services SDK which may soon cause you at least a really annoying message; "this operation is not supported for a relative uri". While it is not fatal and you can ignore it – as a matter of good coding, I tend to get rid of as many warning messages as possible. To fix it, open your machine.config (both x86 and x64 version), and delete the following section:

<endpoint address="" binding="netTcpRelayBinding" 
	contract="IMetadataExchange" name="sb" />

Linking your Silverlight Application to your Webservice

Now the last time we created a Web Service and it is now time to link the Webservice to the Silverlight Application. Right click on the Silverlight application you created last time, and select ‘Add Service Reference’

image

Click on the Discover button and it will search your solution for the Webservice. Give the Namespace a sensible name and click on OK.

Go to the ServiceReferences.ClientConfig file in the Silverlight Client that is created when you link a webservice. Look for the client tag;

<client>
    <endpoint address="http://localhost:51159/SimplicitaServices.svc"
        binding="basicHttpBinding" 
	bindingConfiguration="BasicHttpBinding_ISimplicitaServices"
        contract="SimplicitaServices.ISimplicitaServices" 
	name="BasicHttpBinding_ISimplicitaServices" />
</client>

Change the port number to the same port number that your Azure project executes on. In my development environment this tends to be 81, for yours it might be different.

We nearly have set up the Silverlight application. One last task remains. Silverlight will not retrieve data from some sites, including some webservices unless it has been given permission. You do this by placing a clientaccesspolicy.xml file in the root of the web server. However for this site, which is being run in the virtual server of Visual Studio that in effect means the root of the site. So add a file with that name to your site and insert the following code:

<access-policy>
  <cross-domain-access>
    <policy>
      <allow-from http-request-headers="*">
        >

And there we have it. The Silverlight project is now ready for us to code whatever magic we may wish – which will have to wait till the next part – I’m just about to relax and watch the CSI episode set in a Science Fiction convention!

License

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

Share

About the Author

Paul S. Chapman
Software Developer (Senior) Simplicita Online
United Kingdom United Kingdom
UK based IT Consultant. Started in 1985 selling home computers such as the Sinclair ZX Spectrum, BBC Model B and Commodore 64, and in 1987 moved into development, starting first with Torch Computers, developing software for the XXX UNIX Workstation.
 
Currently developing a new Azure/Silverlight based website/desktop applications for a new startup, hoping to launch in late 2009/early 2010

Comments and Discussions

 
-- There are no messages in this forum --
| Advertise | Privacy | Mobile
Web04 | 2.8.141015.1 | Last Updated 27 May 2009
Article Copyright 2009 by Paul S. Chapman
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid