Search code examples
silverlightsilverlight-4.0wcfwcf-client

Getting Exception when connecting to WCF service from silverlight application


When am trying to connect to the wcf service from silverlight am getting the following exception and here am using the crossdomain.xml and Clinetaccesspolicy file also

Exception : CommunicationException was Unhandel by the usercode

An error occurred while trying to make a request to URI 'http://localhost:3500/WCFService/Service.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.


Solution

  • You have to add the crossdomain policy xml in the hosted application.

    See Cross Domain Policy

    This is because Silverlight is like a client application and it will make wcf service calls to http://../somesite. The crossdomain policy xml says that it accepts calls from otherdomains(i.e Silverlight XAP file which is loaded in the client browser.)