From: https://stackoverflow.com/q/73283828/1188758
I'm getting the exception:
HTTP could not register URL http://+:50005/JTCrawlerAppServer/ because TCP port 50005 is being used by another application.: The process cannot access the file because it is being used by another process
This is running in a WPF app. It ran fine last week, and runs fine on another computer, so I don't know what changed. I've rebooted, run it as administrator, tried a different port number, and several other suggestions from StackOverflow, but no change. Running "netstat -o -n -a" shows no one else on that port. Running "netsh http show url" shows that I should have permission:
Reserved URL : http://+:50005/
User: \Everyone
Listen: Yes
Delegate: No
SDDL: D:(A;;GX;;;WD)
Here's the relevant app.cfg and C# code:
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior name="">
<serviceMetadata httpGetEnabled="true" httpsGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="false" />
</behavior>
</serviceBehaviors>
</behaviors>
<services>
<service name="JTCrawlerApp.JTCrawlerAppService">
<endpoint address="" binding="basicHttpBinding" contract="JTCrawlerApp.IJTCrawlerAppService">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
<host>
<baseAddresses>
<!-- Don't let this through the firewall!! -->
<add baseAddress="http://localhost:50005/JTCrawlerAppServer" />
</baseAddresses>
</host>
</service>
</services>
</system.serviceModel>
public class RunWebServiceCommand : BaseCrawlerCommand
{
// Implementatiion data.
public static string ServerEndpoint = "JTCrawlerAppServer";
protected ServiceHost Host;
// ...
protected bool OnInitializeWebService()
{
try
{
Host = new ServiceHost(typeof(JTCrawlerAppService));
// Service host is opened on the UI thread
Host.AddServiceEndpoint(
typeof(IJTCrawlerAppService),
new WSHttpBinding(),
ServerEndpoint);
Host.Open();
PutLogMessage("RunWebServiceCommand: Service started.");
return true;
}
catch (Exception exc)
{
PutExceptionErrorLogMessage("Error starting JTCrawlerApp web service", exc);
}
return false;
}
}
Here is the stack trace from the exception:
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.TransportChannelListener.OnOpen(TimeSpan timeout)
at System.ServiceModel.Channels.HttpChannelListener`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.Channels.CommunicationObject.Open()
at JTCrawlerApp.Commands.RunWebServiceCommand.OnInitializeWebService() in C:\JTLanguage\JTCrawlerApp\Commands\RunWebServiceCommand.cs:line
It's curious the duplicate CommunicationObject.Open calls. Is it because it's switching to another thread?