WCF Impersonation With Client

If you have a service that uses Windows authentication and you want to impersonate the caller you need to configure the client and the server.

This is the client proxy. You need to give it the correct credentials.

client.ClientCredentials.Windows.ClientCredential.Domain = "DOMAINName";
client.ClientCredentials.Windows.ClientCredential.UserName = "UserName";
client.ClientCredentials.Windows.ClientCredential.Password = "Password";
client.ClientCredentials.Windows.AllowedImpersonationLevel = System.Security.Principal.TokenImpersonationLevel.Impersonation;

The server side looks like this:

using (ServiceSecurityContext.Current.WindowsIdentity.Impersonate())

This impersonate part of the method. This property impersonate all method:

[OperationBehavior(Impersonation = ImpersonationOption.Required)]

Stop Connecting To TFS Automatically On Visual Studio Startup

I often visit customers and work outside the office, means I work disconnected for a while.

It’s laborious when I open VS (2005 or 2008) and waiting for VS to connect automatically to TFS.

Colin Beales has an excellent tip that explains how to stop Visual Studio from automatically connecting to a TFS server when it starts up.

  • Backup your registry
  • Navigate to Team Foundation key:
    • For VS 2005 navigate to: HKEY_CURRENT_USERSoftwareMicrosoftVisualStudio8.0TeamFoundation
    • For VS 2008 navigate to: HKEY_CURRENT_USERSoftwareMicrosoftVisualStudio9.0TeamFoundation
  • Add a registry key “AutoLoadServer” (type DWORD)
  • Setting the value to be 0 (Do not connect automatically or 1 to connect automatically).

Tech-Ed 2008 Talk

As I posted earlier, I’ll speak at the next Tech-Ed in Eilat (6-8 April 2008). This is a great honor for me!

My session will be about MSBuild & VSTS for Database Professional.

The session is title less for now…. If you have any idea – please send it to me.

In order to give you a great presentation, help me to decide about it’s content:

  • Do you have any unanswered questions around VSTS for Database Professionals?
  • What do you like most and least about VSTS for Database Professionals?
  • Do you have any stories you would be willing to share if you used VSTS for Database Professionals?

The next days are critical… I’ll choose a title and announce the session’s agenda. If you have any suggestions, thoughts, advices,wish list, feedbacks or anything – comment it here or send me and email please.


Client Impersonation in WCF

Recently I got a question about impersonation in WCF. What should we do in order to impersonate the client?

It’s simple:

Client Side

// Create a client with given client endpoint configuration
MyServiceClient client = new MyServiceClient();
client.ClientCredentials.Windows.AllowedImpersonationLevel = TokenImpersonationLevel.Impersonation;

Server Side

if (ServiceSecurityContext.Current.WindowsIdentity.ImpersonationLevel == TokenImpersonationLevel.Impersonation ||   ServiceSecurityContext.Current.WindowsIdentity.ImpersonationLevel == TokenImpersonationLevel.Delegation)
// Impersonate.
Console.WriteLine("Impersonating the caller");

LINQ in Action: Book Review

LINQ in Action Recently I got a copy of the book "LINQ in Action" (by Fabrice Marguerie, Steve Eichert, Jim Wooley, and Matt Warren (Foreword))from Manning publishing. Language Integrated Query (LINQ) is a great feature and I wrote about it in this blog.

The book targets the .NET developers who know C# (2.0) or VB.NET (8.0): Whether you don’t know LINQ or you already know – this book is for you. Read it!

For me, it was a pleasure to read it: smooth, clear, didactic and effective.

The book divided into 4 parts:

Getting started, Querying objects in memory, Querying relational data, Manipulating XML and LINQing it all together. The book starts out with a brief of LINQ and then covers the main language enhancements of C# 3.0 and VB.NET 9.0 including: Implicitly typed local variables, Object initializers, Lambda expressions, Extension methods, and Anonymous types. This is a great overview of the features!  There is also introduction covering the history of LINQ, which also presents all the problems that LINQ solves and the design goals of LINQ.

One of the things I really like in this book is that the book doesn’t just focus on LINQ to SQL. If you want to know where LINQ is required – read this book. Also, if you want deep dive into LINQ’s core – this book is for you. The great thing of this book: It’ll satisfy all developers spectrum. One of my favorites chapters in the book is the explanations about extending LINQ.

I think that the last part of the book: LINQing it all together is the best part. It’s a great summary for a great book.

The book absolutely helps you and motivate you to use the technology on your next project.

To summarize: for me, this is the only required book for learning LINQ. if you want to know LINQ and love it, you must read this book!!!

LINQ in Action – 5 stars in Maor’s index.

%d bloggers like this: