Zuker On Foundations

The realm of .NET (WPF, WCF and all around)

October 2009 - Posts

Resolve an Assembly's Public Key

It happens occasionly that I need to extract an assembly's public key. (Usually when I want to use the InternalsVisibleTo assembly attribute)

I find myself constantly searching the web because I keep forgetting :)
I decided to post it here in my blog for future reference:

sn -Tp <assembly DLL name>

Posted Thursday, October 29, 2009 9:46 AM by Amir Zuker | with no comments

תגים:,

Routing a soap message through HTTP protocol with impersonation in WCF

One of the requirements for the sophisticated router facade I built at work was to support Kerberos authentication by using impersonation and delegating the credentials. (Obviously, this will work if all delegation related settings are set up correctly in the domain and so on)

I encountered a specific error while trying to impersonate the caller when the transport was HTTP.
After excessive debugging, I found that WCF carries the incoming authorization HTTP request properties in the message properties collection. If you impersonate the caller and don't clear this property, it will not affect the credentials being passed to the backend service. This is why it happens only when using the HTTP protocol.

Here is the code that made it all work:

 

            if (context.Session.Router.ShouldImpersonate)

            {

                if (context.Session.TargetEndpoint.Transport == RouterTransport.Http

                    && message.Properties != null && message.Properties.Count > 0

                    && message.Properties.ContainsKey(HttpRequestMessageProperty.Name))

                {

                    HttpRequestMessageProperty pp = message.Properties[HttpRequestMessageProperty.Name] as HttpRequestMessageProperty;

 

                    if (pp != null)

                    {

                        pp.Headers.Remove("Authorization");

                    }

                }

 

                return ServiceSecurityContext.Current.WindowsIdentity.Impersonate();

            }

Posted Friday, October 02, 2009 1:39 PM by Amir Zuker | with no comments

תגים:,

How to determine if a console window exists for the current process

If you need to determine whether there's a console window for the current process, you can do it as follows: 

        [DllImport("kernel32.dll", SetLastError = true)]

        private static extern IntPtr GetConsoleWindow();

 

        internal static bool HasConsoleWindow()

        {

            return GetConsoleWindow() != IntPtr.Zero;

        }

Posted Friday, October 02, 2009 12:17 PM by Amir Zuker | with no comments

תגים:,