Silverlight Cross Domain Issue

By admin on Nov 12 2008 | 19 Comments

I'm doing some Silverlight Development and I ran into a wacky issue (or so it seemed at the time).

The Silverlight app would connect to a Java Web Service and get some data (XML). The end result is that this Silverlight app will talk to Java Web Services and the xap file sit on a java web server and be downloaded to the client. During development its done on Windows Machines/VM's (of course). However, when we connected to the service, it would bomb with a Security Exception as follows:

 

A first chance exception of type 'System.ServiceModel.CommunicationException' occurred in System.ServiceModel.dll

Additional information: An error occurred while trying to make a request to URI 'http://example.org:7001/beans/TestWebServiceBean'. 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. Please see the inner exception for more details.

At first glance this looks like an issue with the services clientaccesspolicy.xml file. But looking at the requests through fiddler or Web Dev Helper we can see that an HTTP success (200) was occurring for the requests of those files. They were coming back as expected.

 

CAS: True Smoke and Mirrors

The problem was due to the fact that we running Silverlight under the Test html page from the file system. So it would look something like this:

C:\SVNHome\path\to\project\Bin\Debug\TestPage.html

The Silverlight app would call a web service on the network or Internet. Them, BOOM all hell would break loose. Security exceptions flying around like snowflakes in Minnesnowta.

It looks like this was an issue with Code Access Security. Now I'm not exactly 100% sure where in the CAS stack this error occurred, but I do know that the local file was in a different zone than the Internet zone and when executing code in different zones you run into tons of CAS issues (SecurityExceptions). <Sarcasm>Read more about the super exciting world of CAS here </Sarcasm>. 


So I created a ASP.NET Web App and linked the Silverlight app with the Web App. I fired up the test page which now looks like this:

http://localhost:3399/SilverlightApplicationWevSvcTestTestPage.aspx

BOOM! The app worked just like it should have. Looks like a definite culprit of the deadly CAS. :)

:)

Post info

Tags:
Categories: Silverlight , WCF

Comments

John
John United States on 1/15/2009 3:34 PM This was a big help. None of the posts to various Silverlight forums suggested the test page as the problem.

The exception information from Vs2008 was as follows:
Outer Exception:
System.ServiceModel.CommunicationException: An error occurred while trying to make a request to URI 'http://lasshlld324:8000/basic'. 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.

InnerException:  
System.Security.SecurityException ---> System.Security.SecurityException: Security error.
   at System.Net.BrowserHttpWebRequest.InternalEndGetResponse…


This kind of "turn the corner" solution is very much appreciated.

--John
Donn
Donn United States on 1/15/2009 4:27 PM Glad it helped!
Layla
Layla Norway on 1/20/2009 4:13 AM Thanks a lot, I had been googling this error for a while when I found your post, which was right on my problem! I even had an aspx-project in my solution, but it wasn't set to be the "startup project", so it ran it from the file system anyway. You really helped me today! Smile
Matti
Matti on 1/25/2009 3:27 AM Hey,

Reading this led me to the solution which I had been searching for days. Thank you!

--
Matti
Jeff
Jeff Australia on 2/27/2009 8:15 AM Finally an answer to my problem! Thanks a lot.

If you go to the page via the http address, how do you debug the app? Its now longer running through VS2008 and the breakpoints and stuff don't seem to work.
Donn Felker
Donn Felker on 2/27/2009 1:03 PM @Jeff - Are you starting the app with F5? If so, it should work. If not, you can connect the debugger to the instance of your browser through Debug -> Attach To Process.

Good luck!
Jeff
Jeff Australia on 2/27/2009 2:23 PM Yes I am but that just brings up the c:\...testpage.html. I have to then type in an http address to redirect to a page that will work.
Donn Felker
Donn Felker on 2/27/2009 2:36 PM Is your web project (that houses the html file) set to run the development web browser? Right click on the web project that has the Testpage.html file and check the web tab.
Senthil
Senthil United States on 3/4/2009 12:39 PM hey donn,
am still facing the same problem.
1. have seperated my Silvelight project from the APP.web project.
2. made my APP.web as my start up project and also the aspx page as the start up page.
3. added the clientaccesspolicy.xml file also.
4. my service is hosted in IIS and there is no port issue on the Service side.
5. checked all the bindings are basichttp.

not sure on wwhat to do more to get rid of the error...

let me know ...

Thanks
Senthil
huseyin
huseyin on 3/9/2009 8:24 AM Thanks!
mazzoo
mazzoo on 3/17/2009 5:05 AM Brilliant, thanks a million !
Jeff
Jeff United States on 3/23/2009 9:55 PM Thanks alot!  Alot better than the online help!
Mike Snow
Mike Snow United States on 3/26/2009 1:36 PM I came across this issue today. I remove the service reference to my web service and re-added it to fix the problem. I am still investigating the root issue...
Pieter Theron
Pieter Theron South Africa on 3/27/2009 8:34 AM Hey Donn,

Thanks for your article.

Finally solved my problem with your and Tim Heuer's help.

timheuer.com/.../...cannot-access-web-service.aspx

Sanjit
Sanjit India on 5/15/2009 4:05 PM THANKS A LOT Donn!!! Smile You saved me a LOT OF TIME!! Smile
Thanks!!
Jane Church
Jane Church United States on 5/27/2009 1:10 AM Thanks for this information,Any body want to know the details of home Business then visit on this...
tukang nggame
tukang nggame Indonesia on 5/27/2009 5:02 AM Isssue may be
Zbyszek Swirski
Zbyszek Swirski United Kingdom on 6/3/2009 5:47 PM THANKS A LOT!
I am sorry for shouting, but it really saved me from, I do not know, suicide maybe Smile
I have spend hours today on this and never, ever blamed local policy!
SEO
SEO United States on 6/24/2009 12:56 AM Nice article.I remove the service reference to my web service and re-added it to fix the problem..

Add comment


(Will show your Gravatar icon)

  Country flag

biuquote
  • Comment
  • Preview
Loading