简体   繁体   English

打开Windows服务的防火墙

[英]Opening firewall for a Windows Service

I've a C# service app that needs to be accessed externally by xml-rpc clients. 我有一个需要由xml-rpc客户端外部访问的C#服务应用程序。 It's self hosted via HttpListenerRequest; 它是通过HttpListenerRequest自托管的; not IIS hosted. 没有IIS托管。 (Can't require that servers be IIS enabled) (不能要求服务器启用IIS)

It works fine from a client when the server firewall is turned off OR the ports the app uses are opened. 当服务器防火墙关闭或应用程序使用的端口打开时,它可以在客户端正常工作。 However if I create a firewall exception to enable the app via its name; 但是,如果我创建防火墙例外以通过其名称启用应用程序; its not reachable from the client pc. 它无法从客户端PC访问。 (I've tried both manually enabling the service and adding code to enable the app from my installer.) (我已尝试手动启用该服务并添加代码以从我的安装程序启用该应用程序。)

The reason why I want the application enabled; 我想要启用应用程序的原因; rather than the ports is that the ports may change. 而不是端口是端口可能会改变。 (My app will check a range for available ports on the off chance the default ports are in use). (我的应用程序将在默认端口正在使用的关闭机会上检查可用端口的范围)。 From looking around it appears that any service that isn't fully 'self-hosted' cannot be firewall enabled. 从环顾四周看来,任何未完全“自托管”的服务都无法启用防火墙。

Does anyone know a workaround for this? 有没有人知道这个的解决方法?

不确定语法,但我认为你必须使用netsh这样的东西:

netsh http add urlacl url=http://www.contoso.com:80/MyUri user=DOMAINE\utilisateur listen=yes

Try setting SID type to unrestricted for your service. 尝试将SID类型设置为unrestricted的服务。

Create an Inbound Program or Service Rule 创建入站程序或服务规则

Although the command also permits the value of NONE, that setting means the service cannot be used in a firewall rule as described here. 虽然该命令还允许NONE的值,但该设置意味着该服务不能用于此处所述的防火墙规则中。 By default, most services in Windows are configured as UNRESTRICTED. 默认情况下,Windows中的大多数服务都配置为UNRESTRICTED。 If you change the SID type to RESTRICTED, the service might fail to start. 如果将SID类型更改为RESTRICTED,则服务可能无法启动。 We recommend that you change the SID type only on services that you want to use in firewall rules, and that you change the SID type to UNRESTRICTED. 我们建议您仅更改要在防火墙规则中使用的服务的SID类型,并将SID类型更改为UNRESTRICTED。

It says in the page to use the command 它在页面中说使用该命令

sc sidtype <Type> <ServiceName>

however for me the sc tool itself says to use this: 但是对我来说sc工具本身就是这样说的:

sc sidtype <ServiceName> <Type>

Maybe the service must also run under the "Network Service" account. 也许该服务还必须在“网络服务”帐户下运行。 I did not quite get my service running. 我的服务运行得不好。 EDIT: My problem was due to WCF and not this. 编辑: 我的问题是由于WCF而不是这个。

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

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