views:

44

answers:

2

I realise this question has been asked 100 times, but i've looked through the other answers and can't find a solution that works for me. I have a SilverLight 4 project which contains a WCF service. every time i make a request to the service i get this error:

An error occurred while trying to make a request to URI 'http://localhost:54998/MyService.svc'. 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 read that when running locally, my project will not be using IIS therefore it is pointless adding the clientaccesspolicy.xml in the local host root would be pointless (i have added it anyway just in case). What do I need to do?

EDIT --- This is the inner exception i get

{System.Security.SecurityException: Security error. at System.Net.Browser.BrowserHttpWebRequest.InternalEndGetResponse(IAsyncResult asyncResult) at System.Net.Browser.BrowserHttpWebRequest.<>c_DisplayClass5.b_4(Object sendState) at System.Net.Browser.AsyncHelper.<>c_DisplayClass2.b_0(Object sendState)}

Thanks

A: 

If the Silverlight application is served from a site on a different domain than the one that hosts the WCF service (if the port number changes, this is considered cross domain) you need to place a clientaccesspolicy.xml at the root of the site hosting the WCF service, so that the Silverlight application can access it by:

http://localhost:54998/clientaccesspolicy.xml

and then it will invoke the service:

http://localhost:54998/MyService.svc
Darin Dimitrov
Thanks @Darin. I have tried that but still no luck. If they are both running from the same solution, locally, They shoudnt even be cross domain should they?
Ben
It depends, whether they are hosted in different web projects.
Darin Dimitrov
+1  A: 

Sounds like you need to merge the web service project into the web site project that is serving the Silverlight application to the client.

Rowland Shaw