• WCF跨域 这可能是由于试图以跨域方式访问服务而又没有正确的跨域策略,或策略不适用于 SOAP


    尝试向 URI“http://localhost:8001/AccountService.svc”发出请求时出错。这可能是由于试图以跨域方式访问服务而又没有正确的跨域策略,或策略不适用于 SOAP 服务。您可能需要与该服务的所有者联系,以发布跨域策略文件并确保该文件允许发送 SOAP 相关的 HTTP 标头。出现此错误也可能是由于使用的是 Web 服务代理中的内部类型而没有使用 InternalsVisibleToAttribute 属性。有关详细信息,请参阅内部异常。

    解决方法:

      一、在WCF项目根目录下添加clientaccesspolicy.xml文件


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

    二、在silverlight项目中添加一个中介类ServerManager.cs


    public class ServerManager
        {
            
    private static ServiceWcfClient servicePicture = new ServiceWcfClient();

            
    internal static ServiceWcfClient GetPox()
            {
                
    if (servicePicture.State == System.ServiceModel.CommunicationState.Created)
                {
                    servicePicture.Endpoint.Address 
    = new System.ServiceModel.EndpointAddress("http://localhost:52207/ServiceWcf.svc");
                    
    return servicePicture;
                }
                
    else
                {
                    
    return servicePicture;
                }
            }
        }

    三、实例化实体类的时候一般是这样:ServiceWcfClient clientWcf = new ServiceWcfClient();

    换成:ServiceWcfClient clientWcf = ServerManager.GetPox();

  • 相关阅读:
    记录一次.Net框架Bug发现和提交过程:.Net Framework和.Net Core均受影响
    浅谈 Angular 项目实战
    Angular CLI 升级 6.0 之后遇到的问题
    构建具有用户身份认证的 Ionic 应用
    关于 Angular 跨域请求携带 Cookie 的问题
    使用 ng build 构建后资源地址引用错误的问题
    React 系列教程 1:实现 Animate.css 官网效果
    如何在已有的 Web 应用中使用 ReactJS
    关于浏览器后退操作与页面缓存问题
    三阶魔方公式速记
  • 原文地址:https://www.cnblogs.com/qqflying/p/2225586.html
Copyright © 2020-2023  润新知