Question

I am using a Silverlight application that has net.tcp WCF communications. I would like to self host the ClientAccessPolicy.xml within the ServiceHost and the policy file must be on the root, port 80, as per Silverlight net.tcp requirements (TCP port 4502-4534, etc.). My problem is that when my ServiceHost is running it steals port 80 root from IIS and none of my web pages work.

The code to create the policy endpoint looks like:

host.AddServiceEndpoint(typeof(IPolicyGetter), new WebHttpBinding(), "http://localhost/").Behaviors.Add(new WebHttpBehavior());

When the ServiceHost is running then I can see my http://127.0.0.1/ClientAccessPolicy.xml, but all web sites on port 80 stop working - I see the standard WCF "Endpoint not found" web page generated by the Endpoint. When I turn off the ServiceHost then I can see my web site but the ClientAccessPolicy.xml is gone.

I have tried using a complete path for the endpoint URI:

policyUri.Scheme = "http";
policyUri.Port = 80;
policyUri.Query = "ClientAccessPolicy.xml";
host.AddServiceEndpoint(typeof(IPolicyGetter), new WebHttpBinding(), policyUri.ToString()).Behaviors.Add(new WebHttpBehavior());

but this throws an argument exception. Moving the policy to a subdirectory or a different port will not work because Silverlight only looks at port 80 on the root web directory.

Obviously I can just copy the ClientAccessPolicy.xml into the web root directory and disable the policy endpoint. Is there a way to button-down the endpoint so that it only hijacks calls to ClientAccessPolicy.xml but does not steal the entire IIS port 80?

Was it helpful?

Solution

No, you cannot have two processes listening on the same TCP/IP port. If your ServiceHost is listening on port 80, then it is going to be the only process responding to connections on that port.

Having said that, you can have a "master" process listen on port 80 and redirect connections to "child" processes, but this is beyond the scope and intent of ServiceHost.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top