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’.
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.
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’
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;
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:
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!