K
Karthik Veerabathiran
Guest
I am getting an AddressAlreadyInUseException error when ever I restart my windows service. Issue is not occurring if the service is stopped first and restarted then.
I have googled the problem and tried few suggestions, nothing worked. So I thought to have a fresh perspective from technical experts. Any help would be highly appreciated.
Exception:
Cannot listen on pipe name 'net.pipe://0.0.0.0/SomeService' because another pipe endpoint is already listening on that name.
When Starting service, I will open a service host.
ServiceHost _serverHost = new ServiceHost(this);
_serverHost.Open(); // Exception occurs here.
Start Method:
public void Start(string serviceName)
{
_serviceName = serviceName;
if (_serviceController == null)
{
_serviceController = new ServiceController(_serviceName);
}
try
{
switch (_serviceController.Status)
{
case ServiceControllerStatus.Stopped:
_serviceController.Start();
_serviceController.WaitForStatus(ServiceControllerStatus.Running);
break;
case ServiceControllerStatus.Paused:
_serviceController.Continue();
_serviceController.WaitForStatus(ServiceControllerStatus.Running);
break;
}
}
catch
{
}
}
Stop Method:
public void Stop()
{
try
{
if (_serviceController == null)
{
_serviceController = new ServiceController(_serviceName);
}
if (_serviceController.Status == ServiceControllerStatus.Running)
{
_serviceController.Stop();
_serviceController.WaitForStatus(ServiceControllerStatus.Stopped);
}
}
catch
{
}
}
App.Config:
<endpoint address="" binding="netNamedPipeBinding" contract="Messages">
</endpoint>
<host>
<baseAddresses>
<add baseAddress="net.pipe://0.0.0.0/SomeService"/>
</baseAddresses>
</host>
Continue reading...
I have googled the problem and tried few suggestions, nothing worked. So I thought to have a fresh perspective from technical experts. Any help would be highly appreciated.
Exception:
Cannot listen on pipe name 'net.pipe://0.0.0.0/SomeService' because another pipe endpoint is already listening on that name.
When Starting service, I will open a service host.
ServiceHost _serverHost = new ServiceHost(this);
_serverHost.Open(); // Exception occurs here.
Start Method:
public void Start(string serviceName)
{
_serviceName = serviceName;
if (_serviceController == null)
{
_serviceController = new ServiceController(_serviceName);
}
try
{
switch (_serviceController.Status)
{
case ServiceControllerStatus.Stopped:
_serviceController.Start();
_serviceController.WaitForStatus(ServiceControllerStatus.Running);
break;
case ServiceControllerStatus.Paused:
_serviceController.Continue();
_serviceController.WaitForStatus(ServiceControllerStatus.Running);
break;
}
}
catch
{
}
}
Stop Method:
public void Stop()
{
try
{
if (_serviceController == null)
{
_serviceController = new ServiceController(_serviceName);
}
if (_serviceController.Status == ServiceControllerStatus.Running)
{
_serviceController.Stop();
_serviceController.WaitForStatus(ServiceControllerStatus.Stopped);
}
}
catch
{
}
}
App.Config:
<endpoint address="" binding="netNamedPipeBinding" contract="Messages">
</endpoint>
<host>
<baseAddresses>
<add baseAddress="net.pipe://0.0.0.0/SomeService"/>
</baseAddresses>
</host>
Continue reading...