Click here to Skip to main content
15,887,683 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more: , +
Hi friends,

I'm facing cross domain issue while running the application, error is

System.ServiceModel.CommunicationException: An error occurred while trying to make a request to URI 'hhtp://localhost/Silverlight/Services/abcservice.svc'. This could be due to attempting to access a service in a cross-domain way without a cross-domain policy in the place, or a policy that is unsuitable for soap services.This error may also be created by using internal types in the web service proxy without using the InternalVisibleAttribute attribute. Please see the inner exception. --> blah blah

I searched and found one site [^]that gives solution to the cross domain error sighs!!!!

I done exactly what he says but there is no solution.

I copied a clientaccesspolicy.xml and crossdomain.xml file and placed it in root folder of my project.

But the service(.svc) and its code file (.cs) is placed in my project within a folder named service.

According to the site it says, placing the two xml files in the root folder that has service in it will resolve the issue.
But in my case it does'nt.

what should i do?

Please help me asap!!!!
Any ideas will be greatly appreciated!!!
Posted
Updated 17-Sep-12 19:30pm
v2
Comments
TRK3 17-Sep-12 18:48pm    
You need to give us more information if you expect to get some help.

What is the exact error message/code? When/where does it occur?

You say you "copied a clientaccesspolicy.xml and crossdomain.xml file and placed it in root folder of my project"

(a) those files are supposed to go on the root of the server [which probably isn't the same as the "root folder of my project"]

(b) there is no way to tell if what you have in those files is actually what you need to have in those files.
♥…ЯҠ…♥ 18-Sep-12 1:30am    
I edited my question.....

If you want to call a web-service then the root of the website must have a crossdomain.xml that contains:

XML
<!DOCTYPE cross-domain-policy SYSTEM "http://www.macromedia.com/xml/dtds/cross-domain-policy.dtd">
<cross-domain-policy>
<allow-http-request-headers-from domain="*" headers="*"/>
</cross-domain-policy>



Look at:
http://msdn.microsoft.com/en-us/library/cc197955(v=vs.95).aspx[^]
 
Share this answer
 
v2
Comments
♥…ЯҠ…♥ 18-Sep-12 1:45am    
Thats what i mentioned already i did copying the crossdomain.xml and clientaccesspolicy.xml in remote folder but nothing works out
Kuthuparakkal 18-Sep-12 1:50am    
Not just copying will do :
The article says; "To allow access to an HTTPS service from any Silverlight control hosted over HTTP application, you need to put the "<domain uri=”https://*”"></domain> element inside your <allow-from> element.
♥…ЯҠ…♥ 18-Sep-12 2:00am    
I did that too.... i added for http and https as well.
Kuthuparakkal 18-Sep-12 2:16am    
updated solution, try now
Sometimes something turns in to my way.
I did everything that i can, but stuck with that error.
I searched in google for this error, placed clientaccesspolicy.xml in service folder, placed crossdomain.xml in the same.But nothing works for me.

Then only struck, i try to add port number into my service address path in the ServiceReferences.ClientConfig file.
Earlier it was like
XML
<endpoint address="http://localhost/Services/ManualFileUpload.svc">
binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_ManualFileUpload"
contract="UploadFileService.ManualFileUpload" name="BasicHttpBinding_ManualFileUpload" /></endpoint>

I added port number(4009) to the address like this
XML
<endpoint address="http://localhost:4009/Services/ManualFileUpload.svc">
binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_ManualFileUpload"
contract="UploadFileService.ManualFileUpload" name="BasicHttpBinding_ManualFileUpload" /></endpoint>

Now it works fine and cool in the application.
And now Crossdomain policy error got resolved.

Thanks friends.
 
Share this answer
 
I have also faced the same issue and after a week of my trails got to know that having ClientAcessPolicy.xml and CrossDomainPolicy.xml in the root directory will not serve u r request, the ClientAcessPolicy.xml and CrossDomianPolicy.xml must be sent through the service only.

Follow the below steps to solve this issue

1. Add a new NameSpace in Iservice1.cs as shown below


C#
[ServiceContract(Namespace = "http://ServiceWCF")]

        public interface IPolicyRetriever
         {
           [OperationContract, WebGet(UriTemplate = "/clientaccesspolicy.xml")]

           Stream GetSilverlightPolicy();

           [OperationContract, WebGet(UriTemplate = "/crossdomain.xml")]

           Stream GetFlashPolicy();
         };


2. Now edit the Service1.svc file with edits,



C#
public class PolicyClass : IPolicyRetriever
        {
        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="" *""="">
                                        
                                        <grant-to>
                                            <resource path="" ""="" include-subpaths="" true""="">
                                        
                                    
                                
                            ";
            return StringToStream(result);
        }
        public Stream GetFlashPolicy()
        {
            string result = @"<!--?xml version=""1.0""?-->
                            
                            <cross-domain-policy>
                                <allow-access-from domain="" *""="">
                            ";
            return StringToStream(result);
        }
      }


4. Now Add both the file in the Project Location
5. Better to avoid some of the problems we can add both the file in the Root Folder also
 
Share this answer
 
v3

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