Geeks With Blogs
Paul Chapman .Net Musings

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 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 have 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="*">
        >
        <domain uri="*"/>
      </allow-from>
      <grant-to>
        <resource path="/" include-subpaths="true"/>
      </grant-to>
    </policy>
  </cross-domain-access>
</access-policy>

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!

Posted on Tuesday, May 26, 2009 10:08 PM Silverlight , Windows Azure , CodeProject | Back to top


Comments on this post: Windows Azure, TDS, WCF, Silverlight and a few problems on the way Part IV – The Silverlight Project

# re: Windows Azure, TDS, WCF, Silverlight and a few problems on the way Part IV – The Silverlight Project
Requesting Gravatar...
Wonderful! I was hope you could do silverlight in azure.
Time for me to switch!
Thanks
Left by Mike Greenway on May 29, 2009 5:21 AM

# re: Windows Azure, TDS, WCF, Silverlight and a few problems on the way Part IV – The Silverlight Project
Requesting Gravatar...
Hi Paul,

So far doing well following your document. I do have one question however, can you tell me explicitly where the clientaccesspolicy.xml file goes when using Visual Studios virtual web server. Or maybe a better way to phrase it would be is where is the root of the site.

Thanks for the documentation

Rich
Left by Rich Harrigan on Jun 02, 2009 7:59 PM

# Where to put the clientaccesspolicy.xml
Requesting Gravatar...
Right click on the Webrole or whichever project contains the web service.

Select Add, New Item

Select an Xml file, give it the name clientaccesspolicy.xml and paste the code that is in the article and save it.

That should cover that one.

To be perfectly honest I'm still getting my head around these things. Put that in the root of a real web server and I suspect it will leave the web server a little bit open, but I could be wrong.
Left by Paul on Jun 02, 2009 8:54 PM

# re: Windows Azure, TDS, WCF, Silverlight and a few problems on the way Part IV – The Silverlight Project
Requesting Gravatar...
Hi Paul.

Thanks. everything is working. Look forward to your next installment.

Rich
Left by Richard Harrigan on Jun 03, 2009 1:02 AM

# re: Windows Azure, TDS, WCF, Silverlight and a few problems on the way Part IV – The Silverlight Project
Requesting Gravatar...
Thanks a lot! This was bugging me indeed!!!
Left by Dennis van der Stelt on Jul 13, 2009 6:18 PM

Your comment:
 (will show your gravatar)


Copyright © paulschapman | Powered by: GeeksWithBlogs.net