Jonas Stawski

Everything .NET and More

Silverlight, WCF, and Cross Domain

Last night I was trying to consume a WCF service using Silverlight and I ran into the Cross Domain problem that a lot of people have already ran into. Here’s the message of the exception:

An error occurred while trying to make a request to URI 'http://localhost:1292/WASService/Service.svc/Service'. This could be due to attempting to access a service in a cross-domain way without a proper cross-domain policy in place, or a policy that is unsuitable for SOAP services. You may need to contact the owner of the service to publish a cross-domain policy file and to ensure it allows SOAP-related HTTP headers to be sent. This error may also be caused by using internal types in the web service proxy without using the InternalsVisibleToAttribute attribute. Please see the inner exception for more details.

I have already heard about this error and I knew that it could easily be solved by adding clientaccesspolicy.xml and/or crossdomain.xml to the root of the application. You can find a very detail description of when you are attempting to go across domains in this forum: http://forums.silverlight.net/forums/p/24005/86700.aspx (look for sladapter answer). You can also find more info on by reading the Network Security Access Restrictions in Silverlight. The problem I was having is that both of the files were already in the root of the application.

image

I decided to use firebug to see what was going on:

image

and that’s when it hit me. Silverlight is trying to access the xml files on the root of the webserver, not on the root of the application. My files are located on http://localhost:1292/WASService/clientaccesspolicy.xml and http://localhost:1292/WASService/crossdomain.xml. “Easy fix,” I thought, “just change the files to the root.” The problem is that this is hosted using the WebDevServer (Cassini) and there is no root folder. It turns out that Scott Guthrie wrote about running the app as a root with the local web server. So All I had to do was to bring the properties of the project (F4 on the project) and change the Virtual path from “/WASService” to “/”.

image

Now all I had to do was change the service reference on the Silverlight app and I was up and running in no time.

image

Happy programming!

Comments (13) -

thanks. i solved problem ;)  

Reply

When we access a service in a cross-domain way without a proper cross-domain policy in place, or a policy that is unsuitable for SOAP services. You may need to contact the owner of the service to publish a cross-domain policy file and to ensure it allows SOAP-related HTTP headers to be sent....
Thanks...

Reply

manuel navarro
manuel navarro

Thanks.  You are Great !!!

Reply

This is excellent, thank you so much for sharing!

Reply

Dinesh Chaudhari
Dinesh Chaudhari

Great article. its so simple. Thanx... Smile

Reply

Wow dude....2 days of work...& now it worksSmile)) Thanks!!

Reply

Chris Doan
Chris Doan

Thank you very much for the post, this solved my problem after scratching my head for half a day trying different things such as putting CrossDomain.xml and ClientAccessPolicy.xml in the root of the...application! Great detective work Smile

Reply

GREAT!!!!!

Reply

Thanks, Just placed in inetpub/wwwroot folder it worked.

Reply

Sakkaravarthi and Subhu
Sakkaravarthi and Subhu

Thanks for your great work.

Reply

its nt working

Reply

Thanks. You are Great !!!
I have searching for this from last month... finally I have got... Thanks..

Reply

Add comment

biuquote
Loading