简体   繁体   English

消耗Windows Service中托管的WCF服务时出现HTTP获取错误

[英]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. 当尝试使用Windows服务中托管的WCF服务时出现HTTP Get Error时,由于目标计算机主动拒绝了该连接,因此无法建立连接。但是当我在控制台应用程序中托管同一应用程序时,它可以正常工作。 The issue is getting when application hosting in Windows service.Following code is using to host service. 在Windows服务中托管应用程序时出现问题。以下代码用于托管服务。

 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客户端进行检查

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 如果基于HTTP的服务是在非管理员帐户下启动的,则很可能需要使用以下命令来注册它

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

You can find more details here WCF ServiceHost access rights 您可以在此处找到更多详细信息WCF ServiceHost访问权限

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

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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