Thursday, September 6, 2012

Troubleshooting : HTTP could not register URL http://+:8080/AppName/ServiceName/ because TCP port 8080 is being used by another application.

Reference URL :

http://saravananarumugam.wordpress.com/2011/03/25/http-could-not-register-url-http80temporary_listen_addresses634f73f6-c612-4441-acf8-79ddd5c62f98-because-tcp-port-80-is-being-used-by-another-application/

http://saravananarumugam.wordpress.com/2011/03/01/http-could-not-register-url/

-------------------------------------------------
Content From above URLs
----------------------

Article1
When I used a Duplex channeled binding (wsDualHttpBinding), during the run time I received the following exception.
Exception:
HTTP could not register URL http://+:80/Temporary_Listen_Addresses/634f73f6-c612-4441-acf8-79ddd5c62f98/ because TCP port 80 is being used by another application.
This is because the port 80 is being used by the IIS (the default web site uses Port 80) and the callback from the service attempts to register the same port for communication.
Solution:
The solution to this is to instruct the WCF to use a different port. I had to add the following binding configuration.
    <bindings>
      <wsDualHttpBinding>
        <binding name="wsDualHttpBinding_IGreetingService" 
         clientBaseAddress="http://localhost:8088/clientCallbackUrl">
        </binding>
      </wsDualHttpBinding>
    </bindings>
I also had to specify the bindingConfiguration in endpoint to point to this.
<endpoint address="ws" binding="wsDualHttpBinding" 
contract="DuplexChannel.IGreetingService" 
bindingConfiguration="wsDualHttpBinding_IGreetingService"/>

But unfortunately specifying the clientBaseAddress in service configuration doesn’t take part in the WSDL. As a result clientBaseAddress won’t show up in the client side config. There is no negotiation happening during the runtime either.
So instead of providing the clientBaseAddress in the service side, create the proxy and config as usual and then provide the clientBaseAddress by modifying the client side configuration.
As a result, the client side configuration should typically be looking like this.
<configuration>
    <system.serviceModel>
        <bindings>
            <wsDualHttpBinding>
              <binding name="WSDualHttpBinding_IGreetingService"
                 clientBaseAddress="http://localhost:8088/clientCallbackUrl">
                <security mode="Message">
                  <message clientCredentialType="Windows" 
                          negotiateServiceCredential="true"
                      algorithmSuite="Default" />
                </security>
              </binding>
            </wsDualHttpBinding>
        </bindings>
        <client>
            <endpoint address="http://localhost:54927/GreetingService.svc/ws"
                 binding="wsDualHttpBinding" 
                 contract="GreetingService.IGreetingService"
                 bindingConfiguration="WSDualHttpBinding_IGreetingService"
                 name="WSDualHttpBinding_IGreetingService">
                <identity>
                    <userPrincipalName value="xxx\xxxx" />
                </identity>
            </endpoint>
        </client>
    </system.serviceModel>
</configuration>
Note: By default the Visual Studio would not be able to register even http://localhost:8088/clientCallbackUrl if it is used for the first time due to security constraints.
Refer to HTTP could not register URL for further detail.
An alternate solution to using netsh command is to run the Visual Studio itself in Administrator mode.
Article 2
From here on, I am going try to publish the exceptions/error messages I encounter during the programming and their corresponding resolution.
Exception
I wrote a self host in Visual Studio 2005 in Windows XP. It worked fine.
namespace CalculatorHost
{
    class Program
    {
        static void Main(string[] args)
        {
            ServiceHost host = new ServiceHost(typeof(CalculatorService), 
                new Uri[] { new Uri("http://localhost:8080/Calculator") });
 
            host.AddServiceEndpoint(typeof(ICalculatorService), 
                new BasicHttpBinding(), "");
 
            ServiceMetadataBehavior behavior = 
                new ServiceMetadataBehavior();
            behavior.HttpGetUrl = new 
                Uri("http://localhost:8080/CalculatorService/Meta");
            behavior.HttpGetEnabled = true;
 
            host.Description.Behaviors.Add(behavior);
 
            host.Open();
            Console.WriteLine("Calculator Service Started!!!"+
                "\nPress enter to stop the service");
            Console.ReadLine();
            host.Close();
        }
    }
}
 
I tried to execute the same program in Visual Studio 2010 in Windows 7. But it gave the following exception.
HTTP could not register URL http://+:8080/CalculatorService/Meta/. Your process does not have access rights to this namespace (see http://go.microsoft.com/fwlink/?LinkId=70353 for details).
Note: I received the same exception for http://localhost:8080/Calculator as well.
Solution
The exception itself has offered helping hands on how to register Http Namespace by saying(seehttp://go.microsoft.com/fwlink/?LinkId=70353 for details).
It takes us to the Microsoft’s title “Configuring HTTP and HTTPS”. The exception above resolved by following the solution under “Configuring Namespace Reservations”.
I ran the following command under the .Net Command Prompt.
C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC>netsh http add urlacl url
Url reservation add failed, Error: 5
The requested operation requires elevation (Run as administrator).
I didn’t get through it yet, because by default the .Net command prompt doesn’t have access to register the Http Namespaces.
I reran the .Net command prompt in Administrator mode (Right Click the .Net Command Prompt in Start Menu, and select Run as Administrator).
The same command worked well in Administrator mode.
C:\Windows\system32>netsh http add urlacl url=http://+:8080/CalculatorService/Me
ta/ user=\Everyone
URL reservation successfully added
Another simple alternate to using netsh http command is to run the Visual Studio itself in Administrator mode.
Note: netsh is useful for a verity of work. Refer the following pages for more detail.

No comments: