本文介绍了面对跨域错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 嗨朋友们, 我在运行应用程序时遇到跨域问题,错误是 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 isSystem.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 blahI 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!!!推荐答案<!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 [ ^ ]<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.[ServiceContract(Namespace = "http://ServiceWCF")] public interface IPolicyRetriever { [OperationContract, WebGet(UriTemplate = "/clientaccesspolicy.xml")] Stream GetSilverlightPolicy(); [OperationContract, WebGet(UriTemplate = "/crossdomain.xml")] Stream GetFlashPolicy(); }; 2.现在编辑带有编辑的Service1.svc文件,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 Location5. Better to avoid some of the problems we can add both the file in the Root Folder also 这篇关于面对跨域错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云! 09-05 19:28