0
votes

While Trying to consume a WCF service hosted in a windows service getting HTTP Get Error, No connection could be made because the target machine actively refused it.But when I host Same application in a console application its working fine. The issue is getting when application hosting in Windows service.Following code is using to host service.

 protected override void OnStart(string[] args)
 {
        try
        {
            Uri baseAddress = new Uri("http://localhost:8080/AuditService/");


            host = new ServiceHost(typeof(AuditService), baseAddress);


            ServiceMetadataBehavior smb = new ServiceMetadataBehavior();
            smb.HttpGetEnabled = true;
            smb.MetadataExporter.PolicyVersion = PolicyVersion.Policy15;
            host.Description.Behaviors.Add(smb);

            host.AddServiceEndpoint(typeof(IAuditService), new BasicHttpBinding(BasicHttpSecurityMode.None), baseAddress);

            host.Open();
        }
        catch (Exception)
        {
            host.Abort();

        }
}
2
Check if this works : csharptutorial.in/30/…CodeGuru

2 Answers

1
votes

Are you sure the port is opened?

You can check this using telnet client

telnet machine 8080

If the port is not opened then you can check the exception details to see what is wrong.

If your HTTP-based service is started under non-administrator account then most likely you need to register it with the command like the following

netsh http add urlacl url=http://+:8080/AuditService user=mylocaluser

You can find more details here WCF ServiceHost access rights

0
votes

You open command prompt with administrator and write this text:

netsh http add urlacl url=http://+:8080/AuditService user=Everyone