I have this WCF service which is deployed to windows service:
public partial class Service1 : ServiceBase
{
internal static ServiceHost service = null;
public Service1()
{
InitializeComponent();
}
protected override void OnStart(string[] args)
{
INotificationServiceMode mode = new TcpChatServiceMode();
try
{
service = new ServiceHost(typeof(NotificationService), new Uri("http://localhost:8000/Notification"), new Uri("net.tcp://localhost:808/Notification"));
// Add service behavior
NetTcpBinding tcp = new NetTcpBinding();
service.AddServiceEndpoint(typeof(INotificationService), tcp, "net.tcp://localhost:808/Notification");
ServiceMetadataBehavior metaBehavior = service.Description.Behaviors.Find<ServiceMetadataBehavior>();
if (metaBehavior == null)
{
metaBehavior = new ServiceMetadataBehavior();
metaBehavior.MetadataExporter.PolicyVersion = PolicyVersion.Policy15;
metaBehavior.HttpGetEnabled = true;
service.Description.Behaviors.Add(metaBehavior);
service.AddServiceEndpoint(ServiceMetadataBehavior.MexContractName, MetadataExchangeBindings.CreateMexHttpBinding(), "mex");
}
service.Open();
}
catch (CommunicationException communicationException)
{
throw communicationException;
}
catch (Exception exception)
{
throw exception;
}
finally
{
service.Abort();
}
}
protected override void OnStop()
{
service.Close();
}
}
The consumer application gets error
Could not connect to net.tcp://localhost/Notification/mex. The connection attempt lasted for a time span of 00:00:04.0952640. TCP error code 10061: No connection could be made because the target machine actively refused it 127.0.0.1:808.
What is wrong with that? I am pretty sure that the service is running because when I enabled net.tcp protocol in IIS I got an error that the port is already used by another process
