【问题标题】:Silverlight WCF issue with cross-domain policy file跨域策略文件的 Silverlight WCF 问题
【发布时间】:2011-09-22 03:14:35
【问题描述】:

我已经看到了很多关于这个问题的主题,但没有一个对我有用。我有一个简单的 Silverlight 应用程序。我使用 WCF 服务。当我从服务中调用 GetOrderList 方法时,出现以下错误:

尝试向 URI“https://testserver2.mydomain.org/ORDERNET/WCFServices/OrderService/OrderService.svc”发出请求时出错。这可能是由于在没有适当的跨域策略或不适合 SOAP 服务的策略的情况下尝试以跨域方式访问服务。您可能需要联系服务的所有者以发布跨域策略文件并确保它允许发送与 SOAP 相关的 HTTP 标头。此错误也可能是由于在 Web 服务代理中使用内部类型而不使用 InternalsVisibleToAttribute 属性造成的。有关详细信息,请参阅内部异常。

这是我的代码:

public partial class MainPage : UserControl
    {
        public MainPage()
        {
            InitializeComponent();
            ServiceReference1.ServiceClient sc = new ServiceReference1.ServiceClient();
            sc.GetOrderListAsync("testuser");
            sc.GetOrderListCompleted += new EventHandler<ServiceReference1.GetOrderListCompletedEventArgs>(sc_GetOrderListCompleted);
        }

        void sc_GetOrderListCompleted(object sender, ServiceReference1.GetOrderListCompletedEventArgs e)
        {
            var RESULT = e.Result;
        }
    }

这是我放在 wwwroot 上的客户端访问策略文件:

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

当我运行 fiddler 时,它会找到带有 200 OK (text/xml) 的“clientaccesspolicy.xml”,所以我知道正在查找文件。

可能是什么问题?我有无效的策略文件吗?如果我创建一个控制台应用程序并使用该服务,我可以毫无问题地调用该方法。

有什么想法吗?

【问题讨论】:

  • 在 Fiddler 中,您是否看到请求发送到服务本身?如果是,服务的响应是什么?
  • 我看到 https 协议..它正确吗?尝试使用 http 协议并在您的 clientconfig 文件中使用 httpbinding

标签: wcf silverlight-4.0


【解决方案1】:

我有类似的问题,但服务具有 http 协议,使用 .clientconfig 文件解决。

【讨论】:

    【解决方案2】:

    我注意到您正在使用 HTTPS (https://testserver2.mydomain.org/ORDERNET/WCFServices/OrderService/OrderService.svc)

    您是否尝试过在跨域策略文件中显式添加 https://* uri:

    <domain uri="https://*"/>
    

    如果需要支持http,则两者都加:

    <domain uri="http://*"/>
    <domain uri="https://*"/>
    

    【讨论】:

      【解决方案3】:
      <?xml version="1.0" encoding="utf-8"?>
      <access-policy>
        <cross-domain-access>
          <policy>
            <allow-from http-request-headers="SOAPAction">
              <domain uri="*"/>
            </allow-from>
            <grant-to>
              <resource path="/" include-subpaths="true"/>
            </grant-to>
          </policy>
        </cross-domain-access>
      </access-policy>
      

      Silverlight Cross Domain Web Service Access Error - This could be due to attempting to access a service in a cross-domain way without a proper cross-domain policy in place

      谢谢.....

      【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2010-09-09
      • 2011-03-27
      • 2011-05-03
      • 1970-01-01
      • 2010-12-11
      • 2010-11-24
      • 2011-07-25
      • 1970-01-01
      相关资源
      最近更新 更多