2
votes

I have a WCF Service application created in VS 2010. When I execute it, I got the service page in the following local url

enter image description here

I created another self hosting console application as shown below. It is throwing following exception

HTTP could not register URL. Your process does not have access rights to this namespace (see http://go.microsoft.com/fwlink/?LinkId=70353 for details).

Well, I have no particular interest in the 49609 port number. I just copied it from the other working service.

Now, I have bare minimum rights for running the WCF service. What change I need to do to make the following code to succeed?

Note: There is no chance for me to get the administrator rights in this machine.

Note: I am fine with any port number that will work.

namespace ConsoleApplication1
{
class Program
{
    static void Main(string[] args)
    {
        string baseAddress = "http://" + Environment.MachineName + ":49609/Service";
        ServiceHost host1 = new ServiceHost(typeof(Service1), new Uri(baseAddress));
        host1.AddServiceEndpoint(typeof(ConsoleApplication1.IService1), new BasicHttpBinding(), baseAddress);
        host1.Open();

    }
    static Binding GetBinding()
    {
        BasicHttpBinding result = new BasicHttpBinding();
        return result;
    }

}

}

Service

public class Service1 : IService1
{
    public int Add(int n1, int n2)
    {
        return n1 + n2;
    }
}

[ServiceContract]
public interface IService1
{
    [OperationContract]
    int Add(int n1, int n2);
}
2

2 Answers

6
votes

For console applications to open up incoming (listening) TCP ports using HTTP.sys (which is what the WCF self-hosted scenario uses), they need either to have administrative privileges, or for some account with an administrative privilege to reserve a "namespace" (i.e., a port/path pair) for specific accounts (or all accounts) to use. You mention that you cannot get admin privileges, so you need to get some admin on the machine to grant you access for some namespace which you'll use.

For example, in one of my machines, I never run my VS as administrator (or try my best, as some operations require it), but to start up WCF services, I chose one path (in my case, http://<my-machine-name>:8000/Service), and I reuse that path as the base address of my services. So I had to run, as an admin, the command line below:

netsh http add urlacl url=http://+:8000/Service user=MYDOMAIN\myusername

In your case, you'll need to get an admin in the box to run a similar command for you.