21

I've created and configured an SSL certificate as per these instructions from MSDN. I'm getting the error message that this question lists, but am not sure how to map the accepted answer in that question to my App.config file. The content of the config file, and the service itself worked correctly over http, it's just over https that the problem is occuring.

My App.config file is currently:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <system.serviceModel>
    <bindings>
      <wsHttpBinding>
        <binding name="TransportSecurity">
          <security mode="Transport">
            <transport clientCredentialType="None"/>
          </security>
        </binding>
      </wsHttpBinding>
    </bindings>
    <services>
      <service name="LookupServiceHost" behaviorConfiguration="serviceBehaviour">
        <host>
          <baseAddresses>
            <add baseAddress="https://localhost:54321/MyService"/>
          </baseAddresses>
        </host>
        <endpoint address="" binding="wsHttpBinding" contract="ILookupService" bindingConfiguration="TransportSecurity" />
        <endpoint address="mex" binding="mexHttpsBinding" contract="IMetadataExchange" />
      </service>
    </services>
    <behaviors>
      <serviceBehaviors>
        <behavior name="serviceBehaviour">
          <serviceMetadata httpsGetEnabled="true" />
          <serviceDebug includeExceptionDetailInFaults="False"/>
        </behavior>
      </serviceBehaviors>
    </behaviors>
  </system.serviceModel>
</configuration>

The ErrorException returned in the Windows Event Log:

Service cannot be started. System.ServiceModel.AddressAlreadyInUseException: HTTP could not register URL https://+:54321/MyService/. Another application has already registered this URL with HTTP.SYS. ---> System.Net.HttpListenerException: Failed to listen on prefix 'https://+:54321/MyService/' because it conflicts with an existing registration on the machine.

Could someone give me a pointer as to how to enable this?

Community
  • 1
  • 1
Rob
  • 45,296
  • 24
  • 122
  • 150
  • Since this is .NET, you are not receiving an error message, you are receiving an exception. Please post the complete exception. – John Saunders Sep 10 '10 at 21:10
  • 10
    @John, pedantry aside, I did state that I was receiving the same message (IMO) as the linked post. That said, I've added the specific detail to my question. – Rob Sep 10 '10 at 21:13

4 Answers4

31

I think you are connecting two different settings. Netsh can be used to add certificate for SSL but also to allow application listening on given port without running under admin account. The exception targets second setting. I haven't seen it before but I assume that you have already registered this port for HTTP so lets try to use (and register) HTTPS on another port or replace previous registration.

Edit:

Open command prompt with elevated privileges (As Admin). First check if SSL cert is assigned to correct port:

netsh http show sslcert

Than check if HTTP listening is registered on that port by calling:

netsh http show urlacl 

If so use following command to remove that registration:

netsh http delete urlacl url=http://+:54321/MyService

Add registration again to support listening on HTTPS:

netsh http add urlacl url=https://+:54321/MyService user=domain\userName

Where user is account used to run your Windows service. If it ia a local account use only userName.

Note: Under https, it appears the wildcard must be used in the urlacl. We cannot write https://localhost:8733/... to match Visual Studios default urlacl for http. This probably makes sense since the requested hostname isn't available until after decryption.

Oskar Berggren
  • 5,583
  • 1
  • 19
  • 36
Ladislav Mrnka
  • 360,892
  • 59
  • 660
  • 670
  • could you call out what changes I should make to my .config file / netsh registrations to do that? – Rob Sep 10 '10 at 21:30
  • 1
    it was exactly that - I had the wrong port registered. Throwing myself in at the deep-end is clearly *not* the easiest way to deal with WCF and HTTPS, especially after a glass or two of wine! =) – Rob Sep 13 '10 at 15:53
1

Different apparent cause, but same symptom, for others who find there way to this post.

I ran an application that had "always worked", and after various (not logged since I was not expecting issues) combinations of running it via remote desktop or locally, logging in and out, and replacing it with a recompiled but otherwise identical version with a different version number I got the same "Another application has already registered this URL ...blah, blah".

Apparently (?) the registration was specific to the instance that ran, and persisted across shutdowns of that application. (?) In any case the old Windows adage, "when in doubt reboot" took care of it. With no changes to the app itself it then ran with no complaints. It may be that de-registering, etc., would also have worked. This was under Windows 10 - I have never seen this with earlier versions of Windows.

0

For me I was just not paying attention that I mustn't define the behavior and the service on the same port in the app.config, once I changed the port of the behavior url it worked

refaelo1979
  • 49
  • 2
  • 10
-1

Run the Visual Studio in Run as administrator mode Close the Visual studio application and re open it in administrator mode, That's enough the error is gone. HTTP errors occur when you are running the Visual studio in non admin mode

Lavanya
  • 19
  • 1
  • 5
  • Running Visual Studio as Administrator is *almost never* the right answer. Running *anything* as Administrator is *almost never* the right answer. The accepted answer details the right way to do this. If you run Visual Studio as Administrator, your code will likely need to run in production as Administrator - that is not a place you should, or want to, be – Rob Feb 16 '18 at 11:55
  • I always get this error when I am not debugging the project in admin mode, Once I close the solution and open VS in admin mode and debug the error never occurs – Lavanya Feb 20 '18 at 05:19