8

I already viewed those posts: wcf System.ServiceModel.AddressAlreadyInUseException, Windows Service hosted WCF over HTTPS, Getting AddressAlreadyInUseException after upgrading to .NET 4.5, none of them solve my problem. I have several wcf services in .net 4.5. All of them are in the same Address, i´m getting this exception in the WCF Service host:

System.ServiceModel.AddressAlreadyInUseException: HTTP could not register URL https://+:443/mafawcf01/ServicioAddin.svc/ because TCP port 443 is being used by another application. ---> System.Net.HttpListenerException: The process cannot access the file because it is being used by another process
   at System.Net.HttpListener.AddAllPrefixes()
   at System.Net.HttpListener.Start()
   at System.ServiceModel.Channels.SharedHttpTransportManager.OnOpen()
   --- End of inner exception stack trace ---
   at System.ServiceModel.Channels.SharedHttpTransportManager.OnOpen()
   at System.ServiceModel.Channels.TransportManager.Open(TransportChannelListener channelListener)
   at System.ServiceModel.Channels.TransportManagerContainer.Open(SelectTransportManagersCallback selectTransportManagerCallback)
   at System.ServiceModel.Channels.HttpChannelListener`1.OnOpen(TimeSpan timeout)
   at System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan timeout)
   at System.ServiceModel.Channels.DatagramChannelDemuxer`2.OnOuterListenerOpen(ChannelDemuxerFilter filter, IChannelListener listener, TimeSpan timeout)
   at System.ServiceModel.Channels.SingletonChannelListener`3.OnOpen(TimeSpan timeout)
   at System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan timeout)
   at System.ServiceModel.Security.SecurityListenerSettingsLifetimeManager.Open(TimeSpan timeout)
   at System.ServiceModel.Channels.SecurityChannelListener`1.OnOpen(TimeSpan timeout)
   at System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan timeout)
   at System.ServiceModel.Dispatcher.ChannelDispatcher.OnOpen(TimeSpan timeout)
   at System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan timeout)
   at System.ServiceModel.ServiceHostBase.OnOpen(TimeSpan timeout)
   at System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan timeout)
   at System.ServiceModel.Security.SecuritySessionSecurityTokenAuthenticator.OnOpen(TimeSpan timeout)
   at System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan timeout)
   at System.ServiceModel.Security.SecurityUtils.OpenTokenAuthenticatorIfRequired(SecurityTokenAuthenticator tokenAuthenticator, TimeSpan timeout)
   at System.ServiceModel.Security.SecuritySessionServerSettings.OnOpen(TimeSpan timeout)
   at System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan timeout)
   at System.ServiceModel.Security.SecurityListenerSettingsLifetimeManager.Open(TimeSpan timeout)
   at System.ServiceModel.Channels.SecurityChannelListener`1.OnOpen(TimeSpan timeout)
   at System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan timeout)
   at System.ServiceModel.Channels.DelegatingChannelListener`1.OnOpen(TimeSpan timeout)
   at System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan timeout)
   at System.ServiceModel.Dispatcher.ChannelDispatcher.OnOpen(TimeSpan timeout)
   at System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan timeout)
   at System.ServiceModel.ServiceHostBase.OnOpen(TimeSpan timeout)
   at System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan timeout)
   at Microsoft.Tools.SvcHost.ServiceHostHelper.OpenService(ServiceInfo info)
System.Net.HttpListenerException (0x80004005): The process cannot access the file because it is being used by another process
   at System.Net.HttpListener.AddAllPrefixes()
   at System.Net.HttpListener.Start()
   at System.ServiceModel.Channels.SharedHttpTransportManager.OnOpen()

Here´s my app.congif:

    <host>
      <baseAddresses>
        <add baseAddress="https://localhost:443/mafawcf01/ServicioAddin.svc"/>
      </baseAddresses>
    </host>
  </service>
  <service name="mafawcf01.ServicioPing" behaviorConfiguration="mafawcf01.ServicioPingBehavior">
    <endpoint address=""
              binding="basicHttpBinding"
              bindingConfiguration="secureHttpBinding"
              contract="mafawcf01.IServicioPing">
      <identity>
        <dns value="localhost" />
      </identity>
    </endpoint>
    <endpoint address="mex" binding="mexHttpsBinding" contract="IMetadataExchange" />
    <host>
      <baseAddresses>
        <add baseAddress="https://localhost:443/mafawcf01/ServicioPing.svc" />
      </baseAddresses>
    </host>
  </service>
  <service behaviorConfiguration="mafawcf01.Service1Behavior" name="mafawcf01.ServicioCargue">
    <endpoint address="https://localhost:443/MafaWCF01/ServicioCargue.svc"
      binding="customBinding" bindingConfiguration="myCustomHttpBinding"
      contract="mafawcf01.IServicioCargue" />
    <endpoint address="mex" binding="mexHttpsBinding" contract="IMetadataExchange" />
    <host>
      <baseAddresses>
        <add baseAddress="https://localhost:443/MafaWCF01/ServicioCargue/" />
      </baseAddresses>
    </host>
  </service>
  <service behaviorConfiguration="mafawcf01.Service1Behavior" name="mafawcf01.ServicioValidacionMultiple">
    <endpoint address="https://localhost:443/MafaWCF01/ServicioValidacionMultiple.svc"
      binding="customBinding" bindingConfiguration="transporteSeguro"
      contract="mafawcf01.IServicioValidacionMultiple" />
    <endpoint address="mex" binding="mexHttpsBinding" contract="IMetadataExchange" />
    <host>
      <baseAddresses>
        <add baseAddress="https://localhost:443/MafaWCF01/ServicioValidacionMultiple/" />
      </baseAddresses>
    </host>

I already have the port reserved with this comand:

netsh http add urlacl url=https://+:443/MafaWCF01

And also a certificate associated to the port:

netsh http add sslcert ipport=0.0.0.0:443 certhash={some cert hash} appid={some appid}

do you need any additional information?

Community
  • 1
  • 1
David Acero
  • 254
  • 1
  • 5
  • 14
  • 1
    Take a look with [TCPView](http://technet.microsoft.com/en-us/sysinternals/bb897437.aspx) to see if there's anything already running on that port. – user247702 Dec 16 '13 at 16:15
  • I already did, saw nothing with 443 in Local Port. – David Acero Dec 16 '13 at 16:32
  • Shouldn't `` be ` instead? (Note the removal of the .svc file in the base address). You may have a similar problem with `ServicioPing`. Also, if you're hosting in IIS you don't need to specify the base address - it will be the location of the .svc file for the service. – Tim Dec 16 '13 at 20:46
  • post your `customBinding` section ? – wal Feb 18 '14 at 21:59

3 Answers3

6

In case this helps anyone. I had the same problem while trying to host a wcf service in console application. What I did was open Property of wcf service library (Alt + Enter or right click->Property) then go to WCF Options tab in the Property window and untick "Start WCF Service Host when debugging another project in the same solution". THen the problem is fixed.

dragonfly02
  • 3,403
  • 32
  • 55
  • I did follow the same trick it solved the problem but I was unable to see the WCF service running in my status bar in Windows 10 Home edition. If you think there is something missing. I will highly appreciate it. Thank you @stt106 – Ishwor Khanal Jul 27 '17 at 10:36
5

I have found that a WCF application (or rather http.sys) can hold onto a URL for a little time after it closes down. If you try to restart it immediately, you can get the dreaded AddressAlreadyInUseException because the previous instance of the application is somehow holding it. I found that if I wait a few minutes and try again it can work.

Aria
  • 3,724
  • 1
  • 20
  • 51
saille
  • 9,014
  • 5
  • 45
  • 57
0

I had the same problem.
couldn't find any other app listen on that port, didn't have any conflict whatsoever, yet this error message didn't leave.
it happened right after the service crashed, and since then i couldn't bring it up again.
anyways, after PC restart everything worked. oh well..

RoeeK
  • 1,112
  • 12
  • 23