Thursday, April 15, 2010

Silverlight Cross-Domain Web Services Calls

Target : Silverlight 3.0
Silverlight allows you to make web service calls to web services that are a part of the same website with no restrictions. Additionally, Silverlight allows you to call web services on other web services if they explicitly allow it with a policy file. To make this possible, you must create a file named clientaccesspolicy.xml and place it in the root of your website (for example, in the c:\inetpub\wwwroot directory of an IIS web server).
The clientaccesspolicy.xml file indicates what domains are allowed to access your web service.

You will notice in that file that here I have configured the service to allow connection from a specific URI. You might insert an asteric '*' to allow unlimited access which is not a perfect solution.

You can restrict the resources to share. You can prevent subpaths and so on.

But where to put this xml file ?

This is an important question which I was googling for a long time. Although I wrote that you can put it in the IIS root directory, you will find that this is not the situation when you debug the solution and your project is not added yet to IIS or a specific server. In my condition I was having a silverlight project 'FileServiceApp' , an ASP.net web site that uses the xap file of 'FileServiceApp' and a service project 'WcfFileService' that has the WCF services that I want to use. This file should be used in the 'WcfFileService' Project.

If your services are inside a web project so the xml file should be placed on the root path and not in the assemblies path.

I tried and It works perfectly.




3 comments: