I will be hosting a basic HTTP WCF service using Window Service / Service Host. I would like to limit the service to 2 specific window active directory users and these accounts will vary between PRD and DEV environments so they will be set in a config file.
I was wondering what is the best way to do this, I know normally if I was hosting the service using IIS then I could limit it in the Web.config: http://www.rickgaribay.net/archive/2007/04/04/recipe-wcf-basichttpbinding-with-windows-authentication.aspx However since i'm hosting using ServiceHost then I don't believe this is an option.
From what I read it seems possible to do this using PrincipalPermission Declarative attribute at the service class level: http://msdn.microsoft.com/en-us/library/vstudio/ms731200(v=vs.100).aspx However I'm not too clear whether this will pass the window account of window service or the account which made the HTTP request. What I need is to pass the HTTP request account. Also, with declartive attributes, is it possible to use a config file attribute rather than a hard coded one?
Any suggestions, if you need any more info then let me know.
Open the Computer Management Windows applet. Create a Windows group that contains the specific Windows users to which you wish to give access. For example, a group can be called “CalculatorClients”. Configure your service to require ClientCredentialType = “Windows”.
There are three types of hosting environments for WCF services: IIS, WAS, and self-hosting. The term “self-hosting” refers to any application that provides its own code to initialize the hosting environment. This includes console, Windows Forms, WPF, and managed Windows services.
This is referred to as a self hosting WCF service, the exact meaning of Self Hosted is that it hosts the service in an application that could be a Console Application or Windows Forms and so on. Earlier we saw what a WCF Service is in the . Net environment. We can host a WCF service in IIS and a Windows service also.
Try to use Role-Based authorization. http://msdn.microsoft.com/en-us/magazine/cc948343.aspx#id0070004
I found the following article suitable for what I needed, basically it involved authorisation using a behavior: http://allen-conway-dotnet.blogspot.co.uk/2010/01/how-to-create-aspnet-windows.html
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With