views:

473

answers:

1

I have two machines, we'll call them machine A and machine B. Machine B is running a Windows service written in C#.net, as the Local System account. Machine A tells machine B's service (using WCF) to open a file located on the network. Since local system is not a network user, it does not have access to network files, and is unable to open the file. Currently, I am reading files from machine A and serializing them as strings to machine B, and then writing them locally on B. I've considered making a generic network account for machine B, so it can have access to the network, however this is undesirable. Is there any way I can make machine B open files using the user account of machine A? I've taken a look at the system security principal's identity classes, would this be a case to use them?

+3  A: 

MSDN - How to: Impersonate a Client on a Service

Impersonating a client on a Windows Communication Foundation (WCF) service enables the service to perform actions on behalf of the client. For actions subject to access control list (ACL) checks, such as access to directories and files on a machine or access to a SQL Server database, the ACL check is against the client user account

Also don't forget to configure your service to use Windows Authentication and use a supported binding.

Pop Catalin
Okay, looks like I've got it mostly working, however when I check client.ClientCredentials.Windows.ClientCredentials.UserName it appears to empty. It looks like this isn't getting my credentials from Active Directory, but everything else appears to behaving as it should.
MGSoto
@MGSoto, ClientCredentials.Windows.ClientCredentials.UserName is not for retrieving client credentials, but for supplying a different set of windows credentials if necessary (basically a set only property), to get the current user use Environment.UserName or System.Windows.Forms.SystemInformation.UserName...but there are other ways also
Pop Catalin
Okay, that makes sense. I was hoping that it would show me what it would consider is the logged in user. Any idea why I still might be getting access denied errors? I'm pretty much following MSDN word for word, the only difference is instead of adding numbers, I'm opening a file.
MGSoto