Thursday, February 28, 2008

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)]

Wednesday, February 27, 2008

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_USER\Software\Microsoft\VisualStudio\8.0\TeamFoundation
    • For VS 2008 navigate to: HKEY_CURRENT_USER\Software\Microsoft\VisualStudio\9.0\TeamFoundation
  • Add a registry key "AutoLoadServer" (type DWORD)
  • Setting the value to be 0 (Do not connect automatically or 1 to connect automatically).

Tuesday, February 26, 2008

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.

Thanks!

Data Compare Does Not List All Tables

VSTS for Database Professionals has a great tools like schema and data compare. I got a lot of questions why schema compare list all tables in the target and source databases, but data compare not.

So, the answer is simple. There are 2 possible reasons to this issue:

  1. The table doesn't have a primary key, unique key, or unique constraint to do the comparison against
  2. The table definitions are different

VSTS for Database Professionals uses a key or index to determine which objects correspond with each other when we use the data compare. If a table or view in the source database has more than one primary key, unique index, or unique constraint that matches that of a table or view in the target database, we can specify which one to use for the comparison on the second page of the New Data Comparison wizard.

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.
using(ServiceSecurityContext.Current.WindowsIdentity.Impersonate())
{
Console.WriteLine("Impersonating the caller");
}
}

Friday, February 22, 2008

TechEd Israel 2008, I'll Talk There

I'll be attending in Eilat's Teched (6-8 April 2008) presenting about VSTS for Database Professionals and Team Build. I'm very excited...

If development is your business,  (or) you are decision maker, (or) ALM interesting you, (or) you suffering with database version management, (or) I'm interesting you... You are more than invited to come to my session... :)

Microsoft  also arranges a meetings with the lecturers - I'll be glad to see you there!

The session will demonstrate full lifecycle of a development team with SCM, including database versions management. The cycle has full build on the branch including the database. The demo will be demonstrate on TFS 2008 and VSTS 2008 Team Suite.

You can visit TechEd home page here.

Saturday, February 16, 2008

Team Build 2008 Property Reference

Aaron Hallberg has posted a great reference to the Team Build 2008 built-in properties. 

You can find it at: http://blogs.msdn.com/aaronhallberg/archive/2008/02/12/team-build-2008-property-reference.aspx

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.

Friday, February 15, 2008

Visual Studio Team System 2008 Database Edition Power Tools

Finally, the “DataDude” team announced the availability of the Power Tools for Visual Studio Team System 2008 Database Edition.

The release includes all the functionality that shipped in 2005 plus:

  • Command line SQL Static Code Analysis execution through MSBuild. This enables SQL Static Code Analysis to be an integrated part of Team Build!
  • Data Generation Wizard; allow users to create a new data generation plan by pointing at an existing database, the plan will be fully configured by the wizard to pull all data from the database using the Sequential Databound Generator. This way users can use an existing data set and only override columns which impose risks because of for example privacy concerns and save about half a day or more of configuring a data generation plan from scratch, one column at the time.
  • File based data generator; this allows you to insert the content of files in to the database (works for string and binary, not for XML yet).
  • XML based data generator; this allows you to generate XML based on an XSD (the XSD has to be provided as file right now, and cannot be selected from database or inherited from the data type).
  • Unique Regular Expression generator; this adds the ability to generator unique values using the RegEx String generator.
  • Refactoring Command Generator has been made available as a MSBuild task for better project build integration so it can be made part of the pre-build and pre-deployment stages in the project. This allows users to automated the results of refactoring to some degree in to the project.
  • Two new test conditions for Database Unit Tests
    • ChecksumCondition – Which you can use to verify that the checksum of the data set returned by a database unit test matches the checksum of an expected data set.
    • ExpectedSchemaTestCondition – Which you use to verify that the column names and data types of the returned data set match expected values.

Download page:
http://www.microsoft.com/downloads/details.aspx?FamilyID=73ba5038-8e37-4c8e-812b-db14ede2c354&displaylang=en

Installer download:
http://download.microsoft.com/download/f/b/8/fb8d1c0d-c0c4-4004-ab86-12396b2a3ee3/VSTSDB2008PT.msi

Documentation download:
http://download.microsoft.com/download/f/b/8/fb8d1c0d-c0c4-4004-ab86-12396b2a3ee3/Power Tools 2008.doc

In the following weeks I'll start to record screencasts and writing some posts about this release.

Enjoy!!

Friday, February 1, 2008

TeamBuild 2008 - SetBuildProperties Task

SetBuildProperties task is one of the new tasks that shipped in Team Build 2008. With this task we can modify properties of a BuildDetail object directly from MSBuild's TfsBuild.proj script.

The SetBuildProperties task is defined in the Microsoft.TeamFoundation.Build.Tasks.VersionControl.dll.

The available properties are:

Property Description
LabelName Specifies the label name.
DropLocation Specifies the drop location. (shared folder to which the build account has read/write privileges)
Quality Specifies the build quality.
TestStatus Specifies the test status. Valid values are Succeeded, Failed, and Unknown.
Status Specifies the build status. Valid values are NotStarted, InProgress, Succeeded, PartiallySucceeded, Failed, and Stopped.
BuildNumber Specifies the build number.
TeamFoundationServerUrl Specifies the Team Foundation Server URL. For example, http://MyServer:8080.
BuildUri Specifies the build URI.
CompilationStatus Specifies the compilation status. Valid values are Succeeded, Failed and Unknown.

Usage:

<SetBuildProperties
BuildNumber="$(BuildNumber)"
BuildUri="$(BuildUri)"
DropLocation="$(DropLocation)" />