views:

1413

answers:

6

I am going to be coding up a windows service to add users to a computer (users with no rights, ie just for authentication). (As a side note, I plan to use this method.)

I want to be able to call this windows service from another computer.

How is this done? Is this a tall order? Would I be better off just creating a Web Service and hosting it in IIS?

I have some WCF services hosted in IIS on the calling computer (they will do the calling to the proposed windows service). I have found that Hosting in IIS is somewhat problematic, so I would rather not have a second IIS instance to manage unless I need to.

(I will be using Visual Studio 2008 SP1, C# and Windows Server 2003 (for both caller and service host).

Thanks for the help

+1  A: 

If the windows service publishes a remoting interface then it can be accessed via that remoting interface.

Otherwise it's the same as accessing any other process running on a remote machine except that there may be some tools (e.g., sc) with built in support for executing against a remote machine (barring firewall complications).

Any IPC mechanisms applies; sockets, web services, remoting, etc...

Arnshea
the net services suite of commands also usually support remote targets
Arnshea
I like this idea. But remoting is also somewhat difficult (I have only done it once). I will try this is running WCF in a windows service does not work out for me.
Vaccano
A: 

You could create a WCF service which will talk to your Windows service on the remote box. Host the WCF component in IIS (or however you'd like so that you can communicate with it) and then call the WCF component from your remote machine.

Terry Donaghe
+1  A: 

Simply host a WCF service in the Windows Service. You'll then be able to call it remotely.

John Saunders
+2  A: 

You can host a WCF service inside a Windows service. Take a look at the TCP binding (NetTcpBinding class). Both client and server will have to use WCF, but that doesn't sound like it will be an issue with your implementation.

Also, the section entitled "Hosting in Windows Services" in this MSDN article provides a walk-through of the process

scottmarlowe
Thanks for the extra info and links to the MSDN article.
Vaccano
+1  A: 

You could expose a WCF service directly from your windows service. When you start up your windows service, in addition to spinning up any other background processes, you could create an instance of ServiceHost<T> for your service implementation. This would allow you to not only provide WCF access, but also avoid the extra instance of IIS like you requested, and provide TCP, Named Pipes, and WsHttp endpoints. This should give you some nice flexibility in the performance tuning arena, since it sounds like this service will be consumed internally on your network, rather than externally.

jrista
+2  A: 

If you are thinking of hosting a web service in IIS just to communicate with an NT-service on that same machine, that is definitely more trouble than it is worth in this case.

As other answers have indicated you can make a WCF service with the operations you need and host that within the same NT-service that you want to interact with. You can easily secure this with certificates, or user accounts to make sure it is only controlled by the right people/machines.

If you need to control the NT-service itself, there are existing programs such as sc.exe to start, stop, configure, or query the status of your NT-service remotely.

However, you may want to consider seeking a solution without the overhead of creating an custom NT-service and a custom WCF service to interact with it. If you do, the Net User commands (sorry no link - new user limitation) or the AddUsers (see kb 199878/en-us) utility may be sufficient. If your remote "controller" can invoke these commands directly against the target machine you may not have to create any custom software address this need. Additionally you would have less software to maintain and administer on the target machine. You would just be using the built-in OS capabilities and admin utilities.

Finally, you will need to think about the security aspect, NT-services and IIS are usually run under very restricted accounts, many auditors would flip-out over any service running with sufficient permission to create or modify users locally, and especially on other machines. You'll want to make sure that the service could never be used to create users that do have more than the "authenticate" permission you indicated.

Edit: The net user command may not work against another machine's local users, but check out. pspasswd that along with PsExec to create users, should do what you need remotely.

DanO
Thanks DanO. This is the actual link for those that follow after: http://support.microsoft.com/default.aspx/kb/251394
Vaccano