简体   繁体   中英

Getting HTTP Get Error while Consuming WCF Service hosted in Windows Service

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();

        }
}

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

您与管理员打开命令提示符并输入以下文本:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM