I am working on WCF windows application... while restarting the service, I am getting the below exception.
outerType: System.ServiceModel.AddressAlreadyInUseException
outerMessage: "Cannot listen on pipe name 'net.pipe://0.0.0.1/MyService' because another pipe endpoint is already listening on that name."
type: System.IO.PipeException
App.Config file:
<services>
<service name="ServiceName">
<endpoint address="" binding="netNamedPipeBinding" contract="ServiceClient">
</endpoint>
<host>
<baseAddresses>
<add baseAddress="net.pipe://0.0.0.1/MyService"/>
</baseAddresses>
</host>
</service>
</services>
Start Method:
public void Start(string serviceName)
{
_serviceName = serviceName;
if (_serviceController == null)
{
_serviceController = new ServiceController(_serviceName);
}
TimeSpan timeout;
switch (_serviceController.Status)
{
case ServiceControllerStatus.Stopped:
_serviceController.Start();
timeout = TimeSpan.FromMilliseconds(60000);
_serviceController.WaitForStatus(ServiceControllerStatus.Running, timeout);
break;
case ServiceControllerStatus.Paused:
_serviceController.Continue();
timeout = TimeSpan.FromMilliseconds(60000);
_serviceController.WaitForStatus(ServiceControllerStatus.Running, timeout);
break;
}
}
Stop Method:
public void Stop()
{
if (_serviceController == null)
{
_serviceController = new ServiceController(_serviceName);
}
if (_serviceController.Status == ServiceControllerStatus.Running)
{
_serviceController.Stop();
TimeSpan timeout = TimeSpan.FromMilliseconds(20000);
_serviceController.WaitForStatus(ServiceControllerStatus.Stopped, timeout);
}
}
When ever I restarts my service, I will start my Service controller and also open a service host for hosting my service.
_serverHost = new ServiceHost(this); // this points my service name mentioned in App.Config
_serverHost.Open(); // Exception occurs here.
I tried to increase my time out in WaitForStatus() on both Stop() method but it didn't worked out. Any suggestion will be a great help.
Thanks.