Click here to Skip to main content
15,884,473 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi,

I am trying to use a asp.net Web Service which is built in another project which is using mysql database . now i want to add this service to my silverlight application i have added and when i am running this i am getting the following error
<big>An error occurred while trying to make a request to URI 'http://netpeach102/webservices/service.asmx'. 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.</big>


After Searching in google i have added clientaccespolicy.xml and crossdomain.xml in the bin folder of WebService still i am getting the same error.

Thanks,
Posted

You should use cross-domain policy files when accessing third party web services. There are some ways to develop it; I explain a way that it can solve your problem.

Step 1: Create IPolicyRetriever interface

[ServiceContract]
    public interface IPolicyRetriever
    {
        [OperationContract, WebGet(UriTemplate = "/clientaccesspolicy.xml")]
        Stream GetSilverlightPolicy();
        [OperationContract, WebGet(UriTemplate = "/crossdomain.xml")]
        Stream GetFlashPolicy();
    }


Step2 : Implement IPolicyRetriever interface in your service

public class Service1 : IService1, IPolicyRetriever
    {
#region [ IPolicyRetriever Members ]
        Stream StringToStream(string result)
        {
            WebOperationContext.Current.OutgoingResponse.ContentType = "application/xml";
            return new MemoryStream(Encoding.UTF8.GetBytes(result));
        }
        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>";
            return StringToStream(result);
        }
        public Stream GetFlashPolicy()
        {
            string result = @"<?xml version=""1.0""?>
                            <!DOCTYPE cross-domain-policy SYSTEM ""http://www.macromedia.com/xml/dtds/cross-domain-policy.dtd"">
                            <cross-domain-policy>
                                <allow-access-from domain=""*"" />
                            </cross-domain-policy>";
            return StringToStream(result);
        }
        #endregion
}


Tim Heuer describes another way in this video :
http://www.silverlight.net/learn/videos/all/how-to-use-cross-domain-policy-files-with-silverlight/
 
Share this answer
 
v2
You have to put the files in the right place. When I get to work, I'll tell you where I put them for our stuff.
 
Share this answer
 
It needs to go in the ROOT of the domain. This is important as it is not the application root, but the root web.
Even if your app is at mySite.com/myapp, the policy file needs to be at mysite.com/clientaccesspolicy.xml.
Refer:
http://timheuer.com/blog/archive/2008/04/06/silverlight-cross-domain-policy-file-snippet-intellisense.aspx[^]
http://www.netomatix.com/post/2010/03/09/Silverlight-Cross-Domain-Web-Service-Access-Error.aspx[^]

So just check if you are able to access it here: 'http://www.mywebsite.com/clientaccesspolicy.xml' or 'http://www.mywebsite.com/crossdomain.xml'
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900