面对跨域错误 [英] Facing cross domain error

查看:96
本文介绍了面对跨域错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨朋友们,



我在运行应用程序时遇到跨域问题,错误是



System.ServiceModel.CommunicationException:尝试向URI'hhtp://localhost/Silverlight/Services/abcservice.svc'发出请求时发生错误。这可能是由于尝试以跨域方式访问服务而没有在该位置使用跨域策略,或者是不适合soap服务的策略。也可以通过在Web服务中使用内部类型来创建此错误不使用InternalVisibleAttribute属性的代理。请查看内部异常。 - > blah blah



我搜查了一个 site [ ^ ]给出解决方案跨域错误叹息!!!!



我完全按照他说的做了但没有解决方案。



我复制了 clientaccesspolicy.xml crossdomain.xml 文件并将其放在我项目的根文件夹中。



但服务(.svc)及其代码文件(.cs)放在我的项目中名为service的文件夹中。



根据网站它说,将两个xml文件放在其中有服务的根文件夹中将解决问题。

但在我的情况下它没有。



应该是什么我呢?



请尽快帮助我!!!!

任何想法都将不胜感激!!!

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!!!

推荐答案

如果你想调用一个web服务,那么网站的根目录必须有一个包含以下内容的crossdomain.xml:



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

<!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>







请看:

http://msdn.microsoft.com/en-us/library/cc197955(v = VS.95 ).aspx [ ^ ]


有时某些东西会转向我的方式。

我尽我所能,但坚持这个错误。 />
我在谷歌搜索此错误,将clientaccesspolicy.xml放在服务文件夹中,将crossdomain.xml放在同一个。但是没有什么对我有用。



然后只有敲击,我尝试添加端口号到我的ServiceReferences.ClientConfig文件中的服务地址路径。

之前它就像是

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
<endpoint address="http://localhost/Services/ManualFileUpload.svc">
binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_ManualFileUpload"
contract="UploadFileService.ManualFileUpload" name="BasicHttpBinding_ManualFileUpload" /></endpoint>



我在地址中添加了端口号(4009)像这样


I added port number(4009) to the address like this

<endpoint address="http://localhost:4009/Services/ManualFileUpload.svc">
binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_ManualFileUpload"
contract="UploadFileService.ManualFileUpload" name="BasicHttpBinding_ManualFileUpload" /></endpoint>



现在它在应用程序中运行良好且很酷。

现在Crossdomain政策错误得到解决。



谢谢朋友。


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

Thanks friends.


我也面临同样的问题,经过我的小道周已经知道有ClientAcessPolicy.xml和CrossDomainPolicy.x根目录中的ml不能满足您的请求,ClientAcessPolicy.xml和CrossDomianPolicy.xml必须仅通过该服务发送。



按照以下步骤解决此问题



1.在Iservice1.cs中添加新的NameSpace如下所示





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


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

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

           Stream GetSilverlightPolicy();

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

           Stream GetFlashPolicy();
         };





2.现在编辑带有编辑的Service1.svc文件,

< br $>






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



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.现在在项目位置添加两个文件

5.最好避免一些问题,我们可以在根文件夹中同时添加文件



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


这篇关于面对跨域错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆