Nov 16, 2009

S’Zockerpapier het (ned) abgschlage

Don’t quote me on this, colleagues at home, readers, or anybody out there … because I do not even know the source of this Swiss-German saying, but the meaning is the following:

  • something is not as sweet as it has been once

You can apply this to this years PDC give-away:


The traditional bag is missing some potency and this years drinking bottle was made from recyclable plastic only.

Let’s hope this is not foreboding of the upcoming technologies, products and services from Microsoft ;-)

--- Updated ---

Steven Sinofsky must have read my post before his day 2 keynote, where he announced the unbelievable compensation

a Win7, multi-touch, tablet subnote for 5000 attendees. So

  • things are even sweeter than ever before …

What a way to promote multi-touch adoption with developers!

Windows HPC Server 2008 and how to run your jobs

A twelve hours flight to Los Angeles is a very long time that can be used in a couple of way. One is sleeping, using the on board entertainment system (see on the right; so not to sleep) or reading.

One job you come across every couple of years (or even month as did I lately) as a Windows developer is running computational work that last for a couple of minutes, hours or event up to days. Microsoft Windows HPC Server may look promising to replace a lot of your distributed runtime infrastructure code. It contains as a major component a job scheduler I will make some notes about here.


HPC 2008 brings high performance computing in a cluster environment to the Windows platform. A so-called job may contain several tasks, which basically are single executables (a simple sequential program or an already parallel one) you plan to run. There are a lot of ways to (1.) submit your job:

  • Job management console
  • CLI & PowerShell
  • SOA APIs (WCF)
  • COM APIs
  • .NET APIs or
  • WS-HPC Basic Profile (Web service)

Job scheduling (2.) can get quite sophisticated using First-come-first-serve, exclusive scheduling, resource optimizing. Job execution (3.) goes through the states Queued, Running, Finished, Failed or Cancelled. The scheduler decides according to defined requirements which job to run. Failed jobs can get automatically re-run. Jobs can run in parallel on several nodes or on several local CPUs. Tasks are usually not designed to communicate (I may come back to this in another post). Jobs may even get preempted (killed or slowed down to let other jobs be run before).

The head note (which can also be a compute node) acts as the central job management point. Jobs are stored in an underlying SQL-Server (Express?) database and execute under the submitting users account. There exists only one queue for a cluster.

(source: Microsoft)

Job Submission

Jobs get priorities, allocated resources (nodes, CPU and run time), dependency information or node exclusivity upon submission. A job can be submitted from the command line like this:

job new [options] [/f:jobdescriptionxmlfile] [/scheduler:host]

The two primary client user interface tools to use are the Job Management Console and the Administration Console. Jobs defined with the new job wizard can be saved to a job description XML file (that is intended to be used or even automatically generated). Message-Passing-Interface (MPI) executables must be prepended with mpiexec.

(source: Microsoft)

Job input (data) and output (results) can be on the local node or on a file share. Large and static data should be copied to the nodes whereas small and dynamically updated data should be placed centrally. Data should be cut into pieces (fragmented) and run in so-called “sweep”, which is some kind of (for int i = 0; i < 100; i++) – loop index.

Jobs can also be submitted using the .NET API and the Microsoft.Hpc.Server namespace classes Scheduler (to connect and submit), ISchedulerJob job = scheduler.CreateJob(), job.AddTask(t), etc.

Another way is to call the scheduler using Web Services and the HPCPBClient class (hpcbp.CreateAcitivity(jdsl), hpcbp.GetActivityStatuses(), etc.).

Job Scheduling

The most simple scheduling is a FIFO queue. “Backfill” is a method where time windows are used for small jobs to run according to the definitions of the large submitted jobs. The “resource matchmaking” method is done by the scheduler according to compute, network and application requirements. “Job templates” are administrator or system owner predefined jobs that can be used by high performance computing client users.

Microsoft seems to have done a good job when it comes down to security. As mentioned above, jobs are executed under the submitting users account. Credentials are passed during submission and safely (encrypted, etc.) stored to be used when the job needs to run. Credentials are passed by secured .NET remoting channels to the nodes and deleted after the job run.

Picture: The fail-over topology from Microsoft

Please note the HPC 2008 Server supports the MPI Standard by it’s own MS-MPI implementation.

HPC 2008 Server looks reasonable priced at around 500$ per node (as I found out after a quick search). You are getting some Quality-of-Services you probably cannot code yourself for this money. So have a look yourself next time defining IJob, IJobScheduling interfaces in your project.

Nov 6, 2009

IE8 vs. Google Codesearch

Google codesearch ( is great to search for source code. Since installing Internet Explorer 8 recently there is an error on the page. Who’s the culprit:


Webpage error details

User Agent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.0; Trident/4.0; GTB6; SLCC1; .NET CLR 2.0.50727; InfoPath.1; .NET CLR 3.5.21022; .NET CLR 3.5.30729; .NET CLR 3.0.30729)
Timestamp: Fri, 6 Nov 2009 14:45:24 UTC

Message: Not implemented

Line: 339
Char: 257
Code: 0

I found out IE8 compatibility view does the trick:


Google states they are working on it

Oct 27, 2009

F# – sharp what?

I’m really happy with C# as an expressive, powerful and readable language (after recently being somewhat unfaithful with VB.NET). For a customer project doing heavy mathematics I had a look on the suitability of F# for concurrent table- and matrix-oriented math.

(logo from; not found one from Microsoft!?)


On the Microsoft F# Developer Center I got a first overview (e.g. F# will be part of Visual Studio 2010).

F# is a functional, compiled but object-oriented language. An interactive console allows for initial coding:


There is no autocompletion, syntax highlighting or intellisense. Errors are quite understandable however.

Or you can create a new Visual Studio project:


There is useful little video on channel9 that gives a first idea of the language. Since Cobol/Lisp I have not felt so “strange” with a new language …



The installation for VS2008 took some minutes:



In the samples there is a solution called Samples101 that you can build and run:



On the development center site there a book chapter about asynchronous and concurrent programming (Apress). Unfortunately this book is based on an older version. I found some slides from Matthew Podwysocki.

The technique I am interested in is called “asynchronous workflows” (a powerful set of techniques for structuring asynchronous programs in a natural way).

// :

// my first f# concurrent program




// import or open namespaces

open System.IO

open Microsoft.FSharp.Control.CommonExtensions


// define array of key/value pairs

let people = ["Markus", "F# is cool";

               "Jonas", "eff what?";

               "Aaron", "(doing something different)";

               "Elias", "bla bla bla"]


// define a function to be executed asynchonously                      

let myAsync(name:string, comment:string) =

    async {

        System.Console.WriteLine("Waiting {0} ... {1} / {2}", System.Threading.Thread.CurrentThread.ManagedThreadId, name, comment)

        System.Threading.Thread.Sleep 1000       

        System.Console.WriteLine("Waited! {0}", name)



// change the number of threads in the pool

// let ok = System.Threading.ThreadPool.SetMinThreads(10,10)


// start function on thread pool threads

for nm,url in people do



// wait for termination (using the "pass-forward" or "pipe-forward" operator to chain calls)

System.Console.ReadKey() |> ignore

Which seems to run on 2 pool threads (instead of 2 per CPU which would mean 4) !?:


Uncommenting the SetMinThread line above gives a different behavior


F# Summary

  • a language you have to get used to
  • steep learning curve (for a C# guy like me)
  • not widely used yet. Check maintainability and people skills.
  • suited for certain problem domains (like mathematics, analytics, simulation, …); to be preferred to other CLR languages
  • building on existing .NET framework assets
  • well integrated into Visual Studio (even if my often used “go to definition”/F12 does not work)
  • concurrent and asynchronous operation is an integrated part of the language

Oct 14, 2009

ASP.NET MVC 2 Resources

I’ve been asked about MVC tutorials, blogs, how to learn. Here are some useful links to get started for all of you:


Have fun!

Sep 23, 2009

Unit Testing – A Book you have been waiting for

Does your project have low test coverage, unreadable test code, high investments in maintaining unit tests? Do you feel writing unit test being awkward and time consuming, questioning the overall benefit, not trusting some of the unit tests? Ever had discussions about fake/stubs/mocks, what is better Record-Replay or Arrange/Act/Assert (triple A) syntax, where to set up your fakes, differences between unit and integration tests, testing best practices, different tools and test frameworks?

No? Working as a hair dresser or what? Then you can easily forget about the following …

I just finished reading Roy Osherove’s (300 pages) book “The Art of Unit Testing” which is an easy but MUST-READ book, I’ve been waiting for a long time now. You do not have to agree with all of his views, but definitively opens up your mind concerning unit testing.

Go an get it. Or if you are a team lead or manager go and get a stack of it. Your investment will pay back soon!

Sep 22, 2009

VS MSTEST Test Run Deployment Item Error – DLL not trusted

I remember having this error for a couple of times already during the last few years – so I write a post of my own about the solution to the following issue:

Running Visual Studio 2008 (MSTEST) unit tests fails with:

Failed to queue test run '2009-09-22 17:11:11': Test Run deployment issue: The location of the file or directory 'sqlite3.dll' is not trusted.


There were some hints about using the caspol tool to add full trust to the assembly which DID NOT WORK FOR ME:

C:\Program Files\Microsoft Visual Studio 9.0\VC>caspol -m -ag 1.2 -url \\localhost\c$\project\tools\* FullTrust

Microsoft (R) .NET Framework CasPol 2.0.50727.4016
Copyright (c) Microsoft Corporation.  All rights reserved.

The operation you are performing will alter security policy.
Are you sure you want to perform this operation? (yes/no)
Added union code group with "-url" membership condition to the Machine level.

A better approach was:

1. Remove the reference to the dll from VS
2. Shut down VS
3. Right click the assembly (here the sqlite3.dll) und click the UNBLOCK button.
4. Restart Visual Studio
5. Re-add the reference to the file


(thanks to markrob35)

Sep 15, 2009

WLW Syntax Highlighting with CopyAsHtml

Some of my fellow blogger colleagues at my company hinted using SyntaxHighlighter to post source code. As I am using CopyAsHtml (Visual Studio plugin) for quite some time now and found out about the HTML view in Windows Live Writer


I keep sticking to it. Looks much better again:

   21 private void timer1_Tick(object sender, EventArgs e)

   22 {

   23     Color c = ColorUnderCursor.Get();

   24     this.label1.Text = "Color under cursor = " + c.ToArgb().ToString("x8") + " [hex]";

   25     this.label2.Text = c.ToArgb().ToString() + " [int]";

   26 }

Sep 14, 2009

Color under Cursor in C#

To easily “steal” some styles and colors from a given web app, I wrote the following little application to find out the color under the mouse pointer.


And here’s the code for the major parts:

using System;
using System.Drawing;
using System.Runtime.InteropServices;

namespace ColorUnderPixel
    public class ColorUnderCursor
        public static extern uint GetPixel(IntPtr hDC, int XPos, int YPos);

        [DllImport("user32.dll", CharSet = CharSet.Auto)]
        public static extern bool GetCursorPos(out POINT pt);

        [DllImport("User32.dll", CharSet = CharSet.Auto)]
        public static extern IntPtr GetWindowDC(IntPtr hWnd);

        /// <summary>
        /// Gets the System.Drawing.Color from under the mouse cursor.
        /// </summary>
        /// <returns>The color value.</returns>
        public static Color Get()
            IntPtr dc = GetWindowDC(IntPtr.Zero);

            POINT p;
            GetCursorPos(out p);

            long color = GetPixel(dc, p.X, p.Y);
            return Color.FromArgb((int)color);

    public struct POINT
        public int X;
        public int Y;
        public POINT(int x, int y)
            X = x;
            Y = y;

[Update] Please note that the hex values must be reversed to represent a RGB value like in a CSS

background-color: #3b5998;

Human Interaction Workflow

Windows Workflow Foundation 4.0 does not provide explicit framework classes or tools for workflow human interaction (e.g. waiting for a real actor of a workflow to make a decision how to continue).


Therefore we gave the following approach a try:

  1. Create a workflow with a SQL persistence extension that represent an order confirmation process
  2. Send email to actor, including a link to a ASP.NET application, a URL with request argument (the workflow instance id)
  3. Add a pick activity with two pickbranches, each including a aec.CreateNamedBookmark(<bm>)
  4. Create an ASP.NET application page to confirm a process, loading the workflow instance and calling ResumeNamedBookmark(<bm>)

Here a some details.


To block the workflow and wait for human interaction we used the concept of “Bookmarks”. A bookmark is a named point in your workflow to unload and later resume. To create a bookmark and unload we created a simple custom activity:

public class CreateBookmark : NativeActivity
    public InArgument<string> Bookmark { get; set; }

    protected override void Execute(ActivityExecutionContext context)
        context.CreateNamedBookmark(Bookmark.Get(context), new BookmarkCallback(BookmarkCallback));

    private void BookmarkCallback(ActivityExecutionContext executionContext, Bookmark bookmark, object value)

Sending Email

[Credits for this code to Alex]

Before we can unload our workflow we need to send an URL to the human. The link requests a page that resumes our workflow later on.

public class SendMailActivity : CodeActivity
    public InArgument<string> From { get; set; }
    public InArgument<string> To { get; set; }
    public InArgument<string> Subject { get; set; }
    public InArgument<string> Body { get; set; }

    protected override void Execute(CodeActivityContext context)
        var fromAddress = new MailAddress(From.Get(context));
        var toAddress = new MailAddress(To.Get(context));

        var addresses = new MailAddressCollection();

        using (var message = new MailMessage(fromAddress, toAddress))
            message.Subject = Subject.Get(context);
            message.Body = Body.Get(context);

            var mail = new SmtpClient("localhost", 25);

Get Workflow Instance Id

We did not find a simple way to get the workflow instance identifier in our workflow. To work around this we created another simple activity:

public class WorkflowIdActivity : CodeActivity<Guid>
    protected override void Execute(CodeActivityContext context)
       Result.Set(context, context.WorkflowInstanceId);

Pick and Pickbranch

To summarize: we have a workflow that sends a link to a human, persists and unloads. The question is now (the answer has cost me a beer) what WF4 construct to use to continue our workflow; resuming on two parallel branches. We used the pick and pickbranch activities and included a CreateBookmark trigger activity:

      <w:CreateBookmark Bookmark="[‘Accepted’]" />
    <e:SendMailActivity Body="[‘Your order has been accepted’]" From="[‘’]" Subject="[‘Laptop order’]" To="[‘’]" />
      <w:CreateBookmark Bookmark="[‘Rejected’]" />
    <e:SendMailActivity Body="[‘Your order has been rejected’]" From="[‘’]" Subject="[‘Laptop order’]" To="[‘’]" />

The Web Page

Last step is to build a simple web page, including a green and a red button. Note how we parsed the URL argument to get the workflow identifier.

public partial class OrderConfirmationForm : System.Web.UI.Page
    static SqlPersistenceProviderFactory persistenceProviderFactory;
    static AutoResetEvent instanceUnloaded = new AutoResetEvent(false);
    private Guid workflowId;

    protected void Page_Load(object sender, EventArgs e)
       string id = this.Context.Request.Params["id"];
         workflowId = new Guid(id);

    protected void btnAccept_Click(object sender, EventArgs e)

   protected void btnDecline_Click(object sender, EventArgs e)

    private void ResumeWorkflow(string bookmark)

        PersistenceProvider persistenceProvider = persistenceProviderFactory.CreateProvider(workflowId);
        WorkflowInstance instance = WorkflowInstance.Load(new OrderProcessing(), persistenceProvider);

        instance.OnUnloaded = () => instanceUnloaded.Set();

        instance.ResumeBookmark(bookmark, null);


    static void SetupPersistence()
        persistenceProviderFactory = new SqlPersistenceProviderFactory(@"Database=Instances;Integrated Security=True", false, false, TimeSpan.FromSeconds(60));

    static void ClosePersistence()

WIF (aka Geneva) Glossary

Federated claims-based security as implemented in Microsoft Windows Identity Foundation brings a set of terms that are important to understand. Because I did not find a glossary “out there” I put together a list of terms annotated with a definition (copied from other sources like K. Brown or written myself).

[Sorry: partly in German]




a bit of identity information such as name, email address, age, membership in the Sales role, and so on


A security token is a serialized set of claims that is digitally signed by the issuing authority


builds, signs, and issues security tokens according to the interoperable protocols


an application that relies on claims


the .NET Access Control Service features a Resource-STS: that R-STS can be configured for accepting tokens from specific IP-STSs, and perform various claim transformation including emitting authorization claims


Identity provider STS, like Live ID/passport, ADFS, Sun Metro, CA SiteMinder, IBM, Oracle


Issuing authority like Domain Controller, Certificate Authority, Ausweisb├╝ro der Gemeinde/Kanton


Claims transformation rule (input -> output)


“verb├╝nden”, trust, establish base for SSO

Claims transformation

Values of input claims are transferred to output claim values (copied, constants, from claim type to other claim type). Mapping.


Container for rules and token settings (like token renewal, etc.).

Claim type

A URN string describing the meaning of a claim. There are standard claim types; you can add your own.

Action claim

Claim representing an ACS right (e.g. servicebus send/listen/etc.)


Modul/Handler used by an RP to implement special authorization. Also possible to do other claims transformation/mapping.


Azure .NET Services component for Identity und Access Control

Service Bus

Transparent, routed WCF web service through the cloud, providing quality of services.


Sep 9, 2009

Code Contracts in Visual Studio 2010

Currently still a Microsoft DevLabs Project (planned to be included in 4.0/VS2010) – Code Contracts is a very powerful tool “to sue your code”.


Preconditions: Required state for a method to run successfully. Contract.Requires();
Postconditions: Guarantees condition that will always be true upon completion of a method. Contract.Ensures(Contract.Result<int>() != 0);
Assertions: Contract.Assert(); Contract.Assumer();
Object Invariants: guarantees about conditions that will always be true for the objects. [ContractInvariantMethod]protected void ObjectInvariant()

Code Contracts are inherited (seems correct decision according to OO substitution principle), but preconditions cannot be added, postconditions can. Interface contracts can be applied with attributes, passing a class to specifiy contract.

A basic concept is that your IL code is re-written with CC code (like it or not). Code can be statically checked or at runtime. In Visual Studio there is a new project settings tab “Code Contract”.



Unit Test Timeout

A nice feature we were just shown is that a mstest [TestMethod] can get a [Timeout(100)] attribute to allow long-running (hanging) tests from blocking your unit test run for too long:


WF 4.0 Persistence

Day 3 starts with a recap of what we have done so far with WF4, including the

Testing practices

we did. Important here:

  • isolate dependecies (e.g. web service send/receive activities)
  • design workflow for testability (like creating testable sub workflows and putting all the untestable plumbing activities into a top-level workflow

Today we will have a look at the new workflow persistence concepts in WF4.0. There are samples to look at.

Workflow persistence

is a must for long-running workflows. An important concept here are bookmarks which are a kind of marker for unloaded/persisted workflow instances that can be resumed. What was formerly known as workflow services are now extensions. A persistence provider creates a provider to persist your instances. There is one provider for SQL Server at the moment as far as we’ve seen.

static SqlPersistenceProviderFactory persistenceProviderFactory;
persistenceProviderFactory = new SqlPersistenceProviderFactory(@"Data Source=.\SQLEXPRESS; AttachDbFilename=|DataDirectory|\SampleInstanceStore.mdf; Integrated Security=True", false, false, TimeSpan.FromSeconds(60));

// start, unload, run
WorkflowInstance instance = new WorkflowInstance(myWorkflow);
id = instance.Id; 
instance.OnIdle = () => IdleAction.Unload;
instance.OnUnloaded = () => instanceUnloaded.Set();

// load, resume
PersistenceProvider persistenceProvider = persistenceProviderFactory.CreateProvider(id);
WorkflowInstance instance = WorkflowInstance.Load(activity, persistenceProvider);
instance.OnUnloaded = () => instanceUnloaded.Set(); 
instance.ResumeBookmark(readLineBookmark, input);


Code Generation with T4

The text templating engine (tt or t4) is part of the Visual Studio environment for quite a few version now. It can be used to generate static wrapper classes for workflow in and out arguments.

Static code (text) sections are mixed with dynamic C# code to emit the target file. My 3 minute sample here:


Syntax highlighting comes from tangible engineering VS plugin (a free edition exists).

Sep 8, 2009

HelloWorld Workflow Exercise

The task is creating a workflow that requests for a name (2 to 3 chars long) from the console and prints it, saying hello.

Creating a new VS2010 workflow Flowchart console application crashes first time, but restarting allows continuing.

We create a FlowChart workflow with a DoWhile activity, create a ReadlineActivity



assign the result of the code activity (string) to workflow variable (id):


press “F9” to add breakpoint in workflow designer and run it with “F5”:

Enter name:
Enter name:
Enter name:
Hello lem from WF4.0
Press any key to continue . . .

Now, we want to implement best practices and don’t block in an activity, so let’s refactor it to run asynchronous.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Activities;
using System.Threading.Tasks;

namespace HelloWorldWorkflow
    /// <summary>
    /// Asynchronous code activity that does the bookmark plumbing code correctly.
    /// </summary>
    /// <typeparam name="T">Type of the return value.</typeparam>
    public abstract class AsyncCodeActivity<T> : CodeActivity<T>
        /// <summary>
        /// Activity execution method.
        /// </summary>
        /// <param name="context">The code activity context.</param>
        protected override void Execute(CodeActivityContext context)
            var asyncContext = context.SetupAsyncOperationBlock();
            var task = new Task((ac) =>
                var asyncCtx = (AsyncOperationContext)ac;

                T ret = InternalExecute(context);

                asyncCtx.CompleteOperation(new BookmarkCallback(InternalCompleteAsyncWork), ret);
            }, asyncContext);

        /// <summary>
        /// Internal activity execution method.
        /// </summary>
        /// <param name="context"></param>
        /// <returns></returns>
        protected abstract T InternalExecute(CodeActivityContext context);

        /// <summary>
        /// Internal async code activity completion method.
        /// </summary>
        /// <param name="ctx"></param>
        /// <param name="bm"></param>
        /// <param name="ret"></param>
        protected virtual void InternalCompleteAsyncWork(ActivityExecutionContext ctx, Bookmark bm, object ret)
            Result.Set(ctx, ret);

and my ReadlineActivity would look like this:

public class ReadlineActivity : AsyncCodeActivity<string>
    protected override string InternalExecute(System.Activities.CodeActivityContext context)
        Console.Write("Enter name: ");
        string id = Console.ReadLine();
        return id;

Much easier and less error prone!

Workflow Foundation 4.0

Now getting more technical with Alex, we start learning about the new framework and tools.

But first we do an excursion to other workflow tools existing: K2 blackpearl, skelta BPM.NET (looks interesting, 100% embeddable, designer), Aspouse.Workflow for .NET, AddFlow for .NET (looks depricated?!), Nintex Workflow 2007 (runs only in SharePoint).


What’s new: new designer, new runtime, clearer data flow, new activities (no state-chart style yet, but new FlowChart), more activities, XAML only (no XOML), better WCF integration (WorkflowServiceHost, xamlx files for IIS activated workflows, threading based on ThreadPool, Rules and Expressions (as activities, no stand-alone engine yet, no forward-chaining (yet?), no vocabulary support), different programming models (WorkflowElement and WorkflowElement<T> as base type, with return value), bookmarks (set workflow to named idle state: aec.CreateNamedBookmarkus(“bm”, resumeCallback) and workflowInstance.ResumeBookmark(“bm”);), asynchronous operation: aec.SetupAsyncOperationBlock(); t = new Task(…), t.Start(); asyncContext.CompleteOperation(cb).

Backwards compatiblity: WF3 runs under .NET 4.0 (WF3.0), old activities incompatible with WF4.

Now let’s go hands-on.

Business Modeling

Day 2 is starting at 8 am with a very short introduction from Manuel into the modeling of business process. This should give all the foundations to dig into Windows Workflow Foundation 4.0 later today.

“BM is the creation of a model of an abstract but real business”. Like our software models, business models only represent a certain view onto a business. There is no just 1 correct model. “Modellieren = Hervorheben + Weglassen”. Models for an IT architect are typically much more detailed than for the business.

Types of diagrams: Business Use Case (BUCD), Activity, Business Analysis (BAM).

Process: Model –> Document –> Verify (iterate). BM Hamburger: Strategy –> Operations –> IT (business goals) and backwards (verification).

A business process: has a goal, input, output, needs resources, has impact.

Model diagram: shows business actors and business workers, swim lanes, activities, sequences, parallelism/joins, decision nodes, start and end node(s)

BPMN example (one possible notation; quite complex and very detailed; not suitable for business people, this is a model diagram for IT specialists):


BPEL example: very exact; executable model

Sep 7, 2009

.NET ServiceBus Exceptions

I would like to collect some common exceptions from the service bus here in this post.

Wrong solution name:

Unhandled Exception: System.ServiceModel.EndpointNotFoundException: No DNS entri
es exist for host ---> System.Net.Sockets.SocketEx
ception: No such host is known
   at System.Net.Dns.GetAddrInfo(String name)

Wrong password:

Unhandled Exception: System.ServiceModel.FaultException: authN failed: 'mleder'
of PasswordCredential (#<aGuid>)
   at System.ServiceModel.Security.IssuanceTokenProviderBase`1.DoNegotiation(Tim
eSpan timeout)
   at System.ServiceModel.Security.IssuanceTokenProviderBase`1.GetTokenCore(Time
Span timeout)

Timeout (happens quite often as the CTP cloud hosting infrastructure seems to be quite light weight):

Unhandled Exception: System.TimeoutException: The open operation did not complet
e within the allotted timeout of 00:01:00. The time allotted to this operation m
ay have been a portion of a longer timeout. ---> System.TimeoutException: The so
cket transfer timed out after 00:00:59.9098704. You have exceeded the timeout se
t on your binding. The time allotted to this operation may have been a portion o
f a longer timeout. ---> System.Net.Sockets.SocketException: A connection attemp
t failed because the connected party did not properly respond after a period of
time, or established connection failed because connected host has failed to resp
   at System.Net.Sockets.Socket.Receive(Byte[] buffer, Int32 offset, Int32 size,
SocketFlags socketFlags)

Problem with added ConnectionStatusBehavior:

“ConnectionStatusBehavior requires an IChannelListener that exposes IConnectionStatus”

Trying to emit service meta data:

System.ServiceModel.EndpointNotFoundException was unhandled
  Message="Could not connect to TCP error code 10060: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond "
    Server stack trace:
       at System.ServiceModel.Channels.HttpOutput.WebRequestHttpOutput.GetOutputStream()
       at System.ServiceModel.Channels.HttpOutput.Send(TimeSpan timeout)

Cloud not reachable at the moment:

System.ServiceModel.CommunicationException was unhandled
  Message="Unable to reach via TCP (818, 828) or HTTP (80, 443)"
       at Microsoft.ServiceBus.NetworkDetector.ChooseConnectivityModeForAutoDetect(Uri uri)

Service Bus Meta Data

The question came up how to emit WCF service meta data for possible clients. According to hhaaii this is not possible with wsHttRelayBinding but only with netTcpRelayBinding. netTcp did not work with svcutil so I tried the following:

<?xml version="1.0" encoding="utf-8" ?>
        <behavior name="EndpointBehavior">
          <transportClientEndpointBehavior credentialType="UserNamePassword">
              <userNamePassword userName="<solution>" password="<password>" />
        <behavior name="ServiceBehavior">
         <serviceMetadata httpGetEnabled="true" httpGetUrl="meta" />
      <service behaviorConfiguration="ServiceBehavior" name="Microsoft.ServiceBus.Samples.EchoService">
        <endpoint behaviorConfiguration="EndpointBehavior" binding="wsHttpRelayBinding"
          contract="Microsoft.ServiceBus.Samples.IEchoContract" />
        <endpoint address="mex" binding="wsHttpRelayBinding" bindingConfiguration=""
          name="MexEndpoint" contract="IMetadataExchange" />

The service started. Going to the service bus registry, clicking the service asked for my credentials


but then a Fault was generated:


Giving up, sorry.

Service Bus Registry: public discovery

One of the components in a SOA environment is the so-called service registry. A registry lists running services. In .NET Services there is a ATOM feed that shows your current publicly listed services:


The echoservice is only listed when a ServiceRegistrySettings behavior is added to the service endpoint:

IEndpointBehavior serviceRegistrySettings = new ServiceRegistrySettings(DiscoveryType.Public);

Otherwise it is not publicly visible!


Unfortunately I could not add this registry behavior using app.config configuration. The WCF config editor tool does not even reflect on the behavior in the Microsoft.ServiceBus.dll. I’m not sure if I’m doing something wrong or this is not possible yet with July CTP.

Microsoft Azure .NET Services

The upcoming series of posts are dedicated to “Herr Hannes”.
Starting today with the Microsoft Azure platform is Mario, 7.9.09.

The main drivers to go into the Cloud are: Operation, Maintenance, Quality-of-Services, Security.


Windows Azure Platform (source


  • Microsoft Windows Azure (Platform; compute/store/manage; open for 3rd party hosters)
    vs. Azure Services (Live Services, .NET Services, SQL Services, SharePoint Services, Dynamics CRM Services and more)
  • for application and service hosting (in the cloud)
  • Pricing & Licensing (2000 VM hours compute, 50 GB storage, 20 GB network throughput / day), then
    compute 0.12$/hour, storage = 0.15$, SQL Azure 1 GB 10$/month or 100$/month,
    .NET Services 0.15$/100k messages, 0.10$ bandwidth/GB
.NET Services
  • for .NET, Java, Ruby; REST, SOAP, RSS, ATOM. Focus on application integration and access control
    Quality of Services, flexible scale out
Service Bus
  • Patterns: Service Registry, Connectivity (relay or direct), pub/sub
    "abge-space-ter ESB", NAT/firewall traversal, HTTP and TCP (using ports 808, 818, 819, 828)
    Addressing: [http|sb]:// , new schema prefix "sb" for TCP
      One-way connection relays,

Service Connectivity (source:

Azure is building on existing assets such as WCF. WCF is enhanced in two areas:

  1. bindings (see below) and
  2. behaviors

WCF Bindings and new service bus Relay bindings:

BasicHttpBinding (BasicHttpRelayBinding)
WebHttpBinding (WebHttpRelayBinding)
WSHttpBinding (WSHttpRelayBinding)
WS2007HttpBinding (WS2007HttpRelayBinding)
WSHttpContextBinding (WSHttpRelayContextBinding)
WS2007HttpFederationBinding (WS2007HttpRelayFederationBinding)
NetTcpBinding (NetTcpRelayBinding)
NetTcpContextBinding (NetTcpRelayContextBinding)
n/a  (NetOnewayRelayBinding)
n/a  (NetEventRelayBinding)


So let’s do some hands-on. There’s a sample called EchoService in the SDK.

As always with WCF you create a contract:

[ServiceContract(Name = "IEchoContract", Namespace = "")]
public interface IEchoContract
    string Echo(string text);

implement the contract:

[ServiceBehavior(Name = "EchoService", Namespace = "")]
class EchoService : IEchoContract
    public string Echo(string text)
        Console.WriteLine("Echoing: {0}", text);
        return text;           

Configure the self-hosting console application in app.config:

<?xml version="1.0" encoding="utf-8" ?>
      <!-- Application Service -->
<service name="Microsoft.ServiceBus.Samples.EchoService">
        <endpoint contract="Microsoft.ServiceBus.Samples.IEchoContract"
                  binding="netTcpRelayBinding" />

Do the self-hosting:

// Determine the system connectivity mode based on the command line
// arguments: -http, -tcp or -auto  (defaults to auto)
ServiceBusEnvironment.SystemConnectivity.Mode = GetConnectivityMode(args);

Console.Write("Your Solution Name: ");
string solutionName = Console.ReadLine();
Console.Write("Your Solution Password: ");
string solutionPassword = ReadPassword();

// create the endpoint address in the solution's namespace
Uri address = ServiceBusEnvironment.CreateServiceUri("sb", solutionName, "EchoService");

// create the credentials object for the endpoint
TransportClientEndpointBehavior userNamePasswordServiceBusCredential = new TransportClientEndpointBehavior();
userNamePasswordServiceBusCredential.CredentialType = TransportClientCredentialType.UserNamePassword;
userNamePasswordServiceBusCredential.Credentials.UserName.UserName = solutionName;
userNamePasswordServiceBusCredential.Credentials.UserName.Password = solutionPassword;

// create the service host reading the configuration
ServiceHost host = new ServiceHost(typeof(EchoService), address);

// create the ServiceRegistrySettings behavior for the endpoint
IEndpointBehavior serviceRegistrySettings = new ServiceRegistrySettings(DiscoveryType.Public);

// add the Service Bus credentials to all endpoints specified in configuration
foreach (ServiceEndpoint endpoint in host.Description.Endpoints)

// open the service

Console.WriteLine("Service address: " + address);
Console.WriteLine("Press [Enter] to exit");

// close the service

On the client side we are doing a similar thing using the ChannelFactory:

// create the service URI based on the solution name
Uri serviceUri = ServiceBusEnvironment.CreateServiceUri("sb", solutionName, "EchoService");

// create the credentials object for the endpoint
TransportClientEndpointBehavior userNamePasswordServiceBusCredential = new TransportClientEndpointBehavior();
userNamePasswordServiceBusCredential.CredentialType = TransportClientCredentialType.UserNamePassword;
userNamePasswordServiceBusCredential.Credentials.UserName.UserName = solutionName;
userNamePasswordServiceBusCredential.Credentials.UserName.Password = solutionPassword;

// create the channel factory loading the configuration
ChannelFactory<IEchoChannel> channelFactory = new ChannelFactory<IEchoChannel>("RelayEndpoint", new EndpointAddress(serviceUri));

// apply the Service Bus credentials

// create and open the client channel
IEchoChannel channel = channelFactory.CreateChannel();

So what was added to WCF for Azure:

  • the binding (NetTcpRelayBinding)
  • a cloud rendez-vouz address (“sb://”)
  • a behavior (TransportClientEndpointBehavior) to pass Azure solution credentials
  • a behavior for the registry (ServiceRegistrySettings)

Behaviors and credentials above can also be done using config files and the Microsoft Service Configuration Editor tool:


However, the new TransportClientEndpointBehavior has only one property (CrendentialType) that can be edited. Not very useful; hope this will be improved until release.

Sep 3, 2009

Blogging with Windows Live Writer

Not using one of Scot Hanselman’s The Big Ten Life and Work-Changing Utilities is rather provoking. So I decided to give Live Writer a try for blogging (which is infrequent I admit; because time or projects not permitting).

It’s free, it’s WYSIWYG, can insert (well) text,




Map picture


Tool Impression
Live Writer nice and slim


Technorati Tags: ,,,

spellcheck, etc.

Aug 25, 2009

Finally: new WCF 4 Configuration

According to Dr. Nick some long awaited improvements concerning WCF configuration come with .NET 4.0:

- short type names for configuration extensions : have you ever used strong naming and assembly versioning in your project (sure you have)? have you ever implemented a WCF extension (maybe you have)? did you ever have to always change your config files with every new project (assembly) version, because you had to use the assembly qualified type name - including version and token - in the WCF configuration (I did)?! Therefore you probably also added your extension in code only. That's why I love this new one.

- Channel factories with custom configuration: up to now you had two options for your WCF configuration (1. config file 2. create proxy the hard way in code). Now there's a third one (3. write your own serializable/persistable config OBJECT and pass it to channel factory).

Jul 2, 2009

p&p Acceptance Test Engineering Guide

Patterns & Practices J.D. Meier and his team just released a beta of a 209 pages paper about Acceptance testing ("...acceptance testing is the planned evaluation of a system by customers and customer proxies to assess to what degree it satisfies their expectations"). Very important topic.

See here.

Jul 1, 2009

Windows Mobile 6 with C# (compass control)

Actually the textual representation did not look to great. So I decided to look for a free .NET mobile compass control - which I did not find.

Let's hack some dirty user control drawing code:

/// <summary>

/// Paints the control.

/// </summary>

/// <param name="e"></param>

protected override void OnPaintBackground(PaintEventArgs e)




    int penWidth = 5;

    using (Graphics g = this.CreateGraphics())

    using (Pen penBlackThin = new Pen(Color.Black, penWidth - 3))

    using (Pen penBlack = new Pen(Color.Black, penWidth))

    using (Pen penDarkGray = new Pen(Color.DarkGray, penWidth))

    using (Pen penRed = new Pen(Color.Red, penWidth + 3))

    using (Pen penWhite = new Pen(Color.WhiteSmoke, penWidth + 3))

    using (Brush brushDarkGray = new SolidBrush(Color.DarkGray))

    using (Brush brushWhite = new SolidBrush(Color.White))

    using (Brush brushLightGray = new SolidBrush(Color.LightGray))

    using (Brush brushRed = new SolidBrush(Color.Red))


        double radius = (this.ClientRectangle.Width - 50) / 2;

        double radiusInner = (this.ClientRectangle.Width - 70) / 2;

        int xcenter = this.ClientRectangle.Width / 2;

        int ycenter = this.ClientRectangle.Height / 2;

        float halfFont = this.Font.Size / 2;


        // g.Clear(this.BackColor);


        // draw circles

        g.FillEllipse(brushLightGray, penWidth, penWidth, this.ClientRectangle.Width - 2 * penWidth, this.ClientRectangle.Height - 2 * penWidth);

        g.DrawEllipse(penDarkGray, penWidth, penWidth, this.ClientRectangle.Width - 2 * penWidth, this.ClientRectangle.Height - 2 * penWidth);

        g.DrawEllipse(penBlack, 2 * penWidth, 2 * penWidth, this.ClientRectangle.Width - 4 * penWidth, this.ClientRectangle.Height - 4 * penWidth);


        // draw separator lines

        for (int l = 0; l < 16; l++)


            double angle = l * 22.5 + this.Heading;

            double xout = Math.Sin(this.ToRadian(angle)) * radiusInner;

            double yout = Math.Cos(this.ToRadian(angle)) * radiusInner;

            double xin = Math.Sin(this.ToRadian(angle)) * (radiusInner - 2 * this.Font.Size);

            double yin = Math.Cos(this.ToRadian(angle)) * (radiusInner - 2 * this.Font.Size);

            g.DrawLine(penBlackThin, (int)xout + xcenter, (int)yout + ycenter, (int)xin + xcenter, (int)yin + ycenter);



        // draw N, W, E, S

        double x = Math.Sin(this.ToRadian(this.Heading)) * radius;

        double y = Math.Cos(this.ToRadian(this.Heading)) * radius;

        g.DrawString("N", this.Font, brushRed, (float)(xcenter - x) - halfFont, (float)(ycenter - y) - halfFont);

        g.DrawString("S", this.Font, brushRed, (float)(xcenter + x) - halfFont, (float)(ycenter + y) - halfFont);

        g.DrawString("W", this.Font, brushRed, (float)(xcenter - y) - halfFont, (float)(ycenter + x) - halfFont);

        g.DrawString("E", this.Font, brushRed, (float)(xcenter + y) - halfFont, (float)(ycenter - x) - halfFont);


        // draw needle

        g.DrawLine(penWhite, xcenter, ycenter, xcenter, this.ClientRectangle.Height - 50);

        g.DrawLine(penRed, xcenter, 50, xcenter, ycenter);


        // draw digital heading

        g.FillRectangle(brushWhite, (int)(xcenter - 11 * halfFont), (int)(ycenter - 5 * halfFont), (int)(22 * halfFont), (int)(11 * halfFont));

        g.DrawString(string.Format("{0,3:000}°", this.Heading), this.Font, brushRed, xcenter - 4 * halfFont, ycenter - 5 * halfFont);


        // draw height above sea level

        g.DrawString(string.Format("{0,4:0000.0}m", this.Height), this.Font, brushRed, xcenter - 10 * halfFont, ycenter);



which looks about this on the device:

Needs some adjustments, especially to look great on other screen resolutions too. Maybe later ...