wcfnettcpbindingwebhttpbinding

Adding webHttpBinding endpoint to an existing netTcpBinding


I have a working service which exposing netTcpBinding at the following way:

<service name="MetaData.Service.MetaDataServices" behaviorConfiguration="MetaDataServiceBehavior">
        <endpoint address="net.tcp://localhost:5200/MetaDataService" binding="netTcpBinding" bindingConfiguration="MetaDataBinding" contract="MetaData.ServiceContract.IMetaDataService"/>
      </service>

How can I add http endpoint? I tried the following:

<service name="MetaData.Service.MetaDataServices" behaviorConfiguration="MetaDataServiceBehavior">
        <host>
          <baseAddresses>
            <add baseAddress="http://localhost:5280/MetaDataService"/>
          </baseAddresses>
        </host>
        <endpoint address="net.tcp://localhost:5200/MetaDataService" binding="netTcpBinding" bindingConfiguration="MetaDataBinding" contract="MetaData.ServiceContract.IMetaDataService"/>
        <endpoint address="" binding="webHttpBinding"  contract="MetaData.ServiceContract.IMetaDataService"/>
      </service>

    </services>

but got an exception:

HTTP could not register URL http://+:5280/MetaDataService/. Your process does not have access rights to this namespace (see http://go.microsoft.com/fwlink/?LinkId=70353 for details). class name: RemoteProxy method name: Create


Solution

  • Unless you're running the self-hosted process as an administrator (which I'm guessing is not the case, and you have a good reason for that), you won't be able to start listening to HTTP requests in the machine. You'll need to use an administrator command prompt to grant access to your user account to do that, by following the instructions in the page linked in the error message (the link was broken, but it has just been fixed).

    If you are running Windows 7/8/10/Vista/Server 2008, you can use the following command (from an administrator command prompt):

    netsh http add urlacl url=http://+:5280/MetaDataService/ user=DOMAIN\user
    

    Where DOMAIN\user is the user account you're running the process as. You can find it by using the command whoami in the command prompt.

    Once you do that (only once per machine), then you should be able to run it with a non-admin account.