ceebreenk
ceebreenk

Reputation: 1029

Silverlight not finding clientaccesspolicy.xml in Owin self hosted Web Api

I am aware of the hundreds of similar questions about Silverlight and the clientaccesspolicy.xml but I am losing my head here. I've gone through almost all the posts on Stackoverflow, tried most of the suggestions and I'm still stuck.

I have a SL client calling a method in an Owin self-hosted web api. I've simplified my api service to this example, so there is no unnecessary complexity involved. My api is running on port 9000 for this example.

The problem is that I get a 404 error when calling the method in the api. Using Fiddler I can tell that it's not finding the clientaccesspolicy.xml. I've copied the xml file (and crossdomain.xml) to all locations I can think of, and to that of what other posts have suggested.

enter image description here

Can anyone point out my error or help me in the right direction? Here are some snippets:

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>

Program.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();

    }

Service Agent in 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);
        }            
    }

Upvotes: 0

Views: 294

Answers (1)

Emond
Emond

Reputation: 50712

When using self hosting you will have to serve the policy file yourself by listening for the request for the policy and passing back the policy file.

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

Upvotes: 1

Related Questions