【问题标题】:Silverlight not finding clientaccesspolicy.xml in Owin self hosted Web ApiSilverlight 在 Owin 自托管 Web Api 中找不到 clientaccesspolicy.xml
【发布时间】:2014-10-17 23:11:14
【问题描述】:

我知道关于 Silverlight 和 clientaccesspolicy.xml 的数百个类似问题,但我在这里迷失了方向。我几乎浏览了 Stackoverflow 上的所有帖子,尝试了大部分建议,但我仍然卡住了。

我有一个 SL 客户端调用 Owin 自托管 Web api 中的方法。我已将我的 api 服务简化为 this 示例,因此不涉及不必要的复杂性。对于这个例子,我的 api 在端口 9000 上运行。

问题是我在api中调用方法时遇到404错误。使用 Fiddler 我可以看出它没有找到 clientaccesspolicy.xml。我已将 xml 文件(和 crossdomain.xml)复制到我能想到的所有位置,以及其他帖子所建议的位置。

谁能指出我的错误或帮助我朝着正确的方向前进?以下是一些sn-ps:

clientaccesspolicy.xml:

<?xml version="1.0" encoding="utf-8"?>
<access-policy>
  <cross-domain-access>
    <policy>
      <allow-from http-request-headers="SOAPAction">
         <domain uri="http://*"/>        
         <domain uri="https://*"/>
      </allow-from>
      <grant-to>
        <socket-resource port="9000" protocol="tcp" />
        <resource path="/" include-subpaths="true"/>
      </grant-to>
    </policy>
  </cross-domain-access>
</access-policy>

程序.cs

static void Main(string[] args)
    {
        string baseAddress = "http://localhost:9000/";

        Console.WriteLine("Connected..");
        var server = WebApp.Start<Startup>(url: baseAddress);

        Console.ReadLine();
        Console.WriteLine("Disconnecting..");
        server.Dispose();

    }

SL 中的服务代理:

public async Task TestApi()
    {
        try
        {
            HttpClient client = new HttpClient();                

            var response = await client.GetAsync("http://localhost:9000/api/test");
            var result = await response.Content.ReadAsStringAsync();

            ... bla bla bla
        }
        catch (Exception e)
        {
            throw new Exception(e.Message);
        }            
    }

【问题讨论】:

    标签: silverlight-5.0 owin asp.net-web-api2


    【解决方案1】:

    使用自托管时,您必须自己通过侦听策略请求并传回策略文件来提供策略文件。

    见:Cross domain policy file over net.tcp for WCF servicehost and Silverlight 5

    【讨论】:

    • 谢谢,厄诺。我花了很多时间研究,但最终弄清楚了需要什么。
    猜你喜欢
    • 2011-08-22
    • 2019-02-24
    • 2015-01-09
    • 2016-12-15
    • 2011-01-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多