简体   繁体   中英

Opening firewall for a Windows Service

I've a C# service app that needs to be accessed externally by xml-rpc clients. It's self hosted via HttpListenerRequest; not IIS hosted. (Can't require that servers be IIS enabled)

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. (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.

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. By default, most services in Windows are configured as UNRESTRICTED. If you change the SID type to RESTRICTED, the service might fail to start. 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.

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 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.

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