views:

31

answers:

1

Hi,

I am working with a Silvelright App that consumes a WCF service, I have placed a crossdomain and clientaccesspolicy xml's in the wwwroot of the IIS as well as in the application folder!

yet when the client communicates with the service, it throws an error saying;

An error occurred while trying to make a request to URI ‘http://localhost:1528/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 ……

Please help! Thanks

A: 

The clientaccesspolicy.xml needs to be on the same port as your service. It needs to be located at http://localhost:1528/clientaccesspolicy.xml

If you are self hosting the WCF service then you need to host the clientaccesspolicy.xml from within your WCF service. The easiest way I've found to do this is to add a separate service contract that provides an HTTP GET of the clientaccesspolicy.xml.

[ServiceContract()]
public class PolicyRetriever
{
    [OperationContract, WebGet(UriTemplate = "/clientaccesspolicy.xml")]
    public Stream GetSilverlightPolicy()
    {
        string result = @"<?xml version=""1.0"" encoding=""utf-8""?>
        <access-policy>
            <cross-domain-access>
                <policy>
                    <allow-from http-request-headers=""*"">
                        <domain uri=""*""/>
                    </allow-from>
                    <grant-to>
                        <resource path=""/"" include-subpaths=""true""/>
                    </grant-to>
                </policy>
            </cross-domain-access>
        </access-policy>";

        if (System.ServiceModel.Web.WebOperationContext.Current != null)
        {
            System.ServiceModel.Web.WebOperationContext.Current.OutgoingResponse.ContentType = "application/xml";
        }

        return new MemoryStream(Encoding.UTF8.GetBytes(result));
    }
}
Stephan
it helped! I got some more info [different than urs] from http://bit.ly/aPzq68
James
If this solved your problem, please accept as answer
Stephan