Enter To Win a 1-Year MSDN Subscription

I have an MSDN Subscription voucher to give away!  The voucher is good for Microsoft Visual Studio 2010 Ultimate with MSDN subscription and will give you access to many Microsoft products for 1 year.  This is a great benefit to anyone doing development and I believe it now includes monthly time on Azure and Platform AppFabric.

The software is good only for development and testing purposes and this subscription is Not For Resale. 
I will be having a drawing for the voucher on Sunday, October 10th, 2010 at 10:00 PM CST. 

How to enter:

  • Ensure you do not already have an MSDN subscription – this will not do anything for you in that case
  • Email, post to Facebook, or by any other means possible get me a picture or Link to a picture of yourself holding a copy of my new book – Applied Architecture Patterns on the Microsoft Platform or just a picture of the book will work as well.  It must be clear this is a picture of the book and not a digital image of the cover. 
  • Email to <CONTEST CLOSED>
  • If you already bought the book and have not received it yet – simply take a picture of the invoice or forward the invoice to the above email address.
  • No purchase needed to enter.  You do not have to buy the book – if you can find it in a book store or have a friend that owns it that works.  If you can not find a physical copy of the book any place, simply take a picture of the book page on Amazon or Packt website and use that picture to enter.
  • All entries may be posted to this website so keep that in mind when entering.

The winner will be announced on my blog shortly after the drawing and of course I’ll be posting the picture!
I will email the winner the Registration Key for the MSDN Subscription.

I will email the winner the Registration Key for the subscription.  This is subject to all the Terms and Conditions of the MSDN Subscription that may have geographical restrictions or other limitation.

Want more information about the book?  Read a Sample Chapter online at Chapter 12 Debatching Bulk Data or check out the book page on Amazon.com or Packt.

WF4 Activities and Callbacks / Event Handlers

Recently David K contacted me through my blog and shared with me a solution that he came up with for a particular problem that he was able to solve using IWorkflowInstanceExtension and said it would be great if I could do an endpoint.tv episode about it.  David already solved his problem but he wanted to spare you the pain in case you ever have to do this.

Download WF4 Activity Callbacks and Events Example from MSDN Code Gallery

The Problem

Let’s imagine that you have a class library that exposes a type called Gizmo.  This Gizmo type exposes an event that is fired from time to time for some reason (maybe it detects some input from a hardware device) and you want to create an activity that will wait for the Gizmo.Fire event and return the level that was fired.

public class Gizmo

{
public event EventHandler<GizmoEventArgs> Fire;

public void FireGizmo(int level)
{
if (Fire != null)
{
Fire(this, new GizmoEventArgs {Level = level});
}
}
}

Activities cannot just sit around waiting for an event and blocking the workflow thread so we need a way to add an event handler that can handle the event and resume the workflow once it is fired. Also we need to be sure that this works correctly even if the workflow host has a persistence enabled. Because there is no way for an activity to re-establish connections with event handlers when being loaded from persistence we have to avoid being persisted while we have a connection to the Gizmo.Fire event.

The Solution

The solution is to pair the Activity with an Extension.  It works like this.

  1. Create an activity called WaitForGizmo and an extension called WaitForGizmoExtension which implements IWorkflowInstanceExtension
  2. When the Activity is executed it will enter a no-persist zone and let the extension know when it needs to handle the event and set a bookmark
  3. The WaitForGizmoExtension will handle the event and resume the bookmark
  4. When the bookmark is resumed the activity will obtain the out argument values and exit the no-persist scope

This is the right way for dealing with CLR events and callbacks.

The WaitForGizmo activity

public sealed class WaitForGizmo : NativeActivity<int>

{
internal const string BookmarkName = "WaitingForGizmoToBeFired";
private readonly Variable<NoPersistHandle> _noPersistHandle = new Variable<NoPersistHandle>();
private BookmarkCallback _gizmoBookmarkCallback;

public InArgument<Gizmo> TheGizmo { get; set; }

public BookmarkCallback GizmoBookmarkCallback
{
get
{
return _gizmoBookmarkCallback ??
(_gizmoBookmarkCallback = new BookmarkCallback(OnGizmoCallback));
}
}

protected override bool CanInduceIdle
{
get { return true; }
}

protected override void CacheMetadata(NativeActivityMetadata metadata)
{
// Tell the runtime that we need this extension
metadata.RequireExtension(typeof (WaitForGizmoExtension));

// Provide a Func<T> to create the extension if it does not already exist
metadata.AddDefaultExtensionProvider(() => new WaitForGizmoExtension());

metadata.AddArgument(new RuntimeArgument("TheGizmo", typeof (Gizmo), ArgumentDirection.In, true));
metadata.AddArgument(new RuntimeArgument("Result", typeof (int), ArgumentDirection.Out, false));
metadata.AddImplementationVariable(_noPersistHandle);
}

protected override void Execute(NativeActivityContext context)
{
// Enter a no persist zone to pin this activity to memory since we are setting up a delegate to receive a callback
var handle = _noPersistHandle.Get(context);
handle.Enter(context);

// Get (which may create) the extension
var gizmoExtension = context.GetExtension<WaitForGizmoExtension>();

// Add the callback
gizmoExtension.AddGizmoCallback(TheGizmo.Get(context));

// Set a bookmark - the extension will resume when the Gizmo is fired
context.CreateBookmark(BookmarkName, GizmoBookmarkCallback);
}

internal void OnGizmoCallback(NativeActivityContext context, Bookmark bookmark, Object value)
{
// Store the result
Result.Set(context, (int) value);

// Exit the no persist zone
var handle = _noPersistHandle.Get(context);
handle.Exit(context);
}
}

The WaitForGizmoExtension

internal class WaitForGizmoExtension : IWorkflowInstanceExtension

{
private static bool _addedCallback;
private WorkflowInstanceProxy _instance;

#region IWorkflowInstanceExtension Members

public IEnumerable<object> GetAdditionalExtensions()
{
return null;
}

public void SetInstance(WorkflowInstanceProxy instance)
{
_instance = instance;
}

#endregion

internal void AddGizmoCallback(Gizmo gizmo)
{
if (!_addedCallback)
{
_addedCallback = true;
gizmo.Fire += OnGizmoFired;
}
}

internal void OnGizmoFired(object sender, GizmoEventArgs args)
{
// Gizmo was fired, resume the bookmark
_instance.BeginResumeBookmark(
new Bookmark(WaitForGizmo.BookmarkName),
args.Level,
(asr) => _instance.EndResumeBookmark(asr),
null);
}
}

Handling Timeouts

What if Gizmo does not fire? You might want to have a solution where if Gizmo doesn’t fire within some timeout period you do something else. The best way to deal with this is at the workflow level by using a Pick activity with a branch that contains a delay. This ensures that either a Gizmo.Fire event is detected or the Timeout occurs

Book review: Silverlight 4 in Action

Some weeks ago I received a review copy of Silverlight 4 in Action by Pete Brown. Reviewing this book took some time as it weighs in at a hefty 798 pages, who ever said that Silverlight was a small products? That is a lot of material but then the book doesn't assume any prior knowledge of Silverlight at all.

 

The book is divided into 25 chapters in 3 different sections.

The first part, consisting of 10 chapters, is titled "Introducing Silverlight". As the name suggests this covers the basics of Silverlight development. This section is mostly targeted at developers new to Silverlight and covers subjects like what XAML is, how the Silverlight plug-in works with the browser, basic layout and the Silverlight controls and how they work with things like templates.

 

The second part is titled "Structuring your application". This section is divided into 7 chapters and build on top of the first part. In this section there are chapters about data binding, input validation, communicating and even about subjects like MVVM and WCF RIA services. Some of these topics, like for example MVVM, are quite large to begin with and the definitive word hasn't been said about it. In these cases the book is a nice point to get started but no more than that and getting additional information on the Internet is pretty much a requirement. In most cases, like validation. Pete has a pretty solid coverage of the material the book will help you understand what you need to know.

 

The third part is titled "Completing the experience" and consist of a final 8 chapters. This section covers subjects like printing, working with media like smooth streaming or using the webcam and microphone.
There are also chapters on animations, using resources and creating custom controls.

So who is this book for?
With a book this big covering that many topics the book is really targeted at a wide range of developers. It does assume the reader is familiar with C# and the .NET framework but assumes no familiarity with Silverlight at all. So if you are an experienced .NET developer wanting to get into Silverlight this is a good book to start with using part 1. You you are already a Silverlight developer moving from Silverlight 3 to Silverlight 4 this book will also be quite helpful. You will find a lot of material you are already familiar with but also a lot of new material like web cam support and WCF RIA services or extended validation options. In that case this book would be a useful reference to keep handy and read specific chapters from par 2 or 3 when needed.

 

All in all I would recommend getting this book if you are serious about Silverlight 4 development!

 

Enjoy!

BizTalk Patterns part 1 – Asynchronous Aggregation

Developing a BizTalk Server solution can be challenging, and especially complex for those who are unfamiliar with it. Developing with BizTalk Server, like any software development effort is like playing chess. There are some great opening moves in chess, and there are some great patterns out there to start a solution. Besides being an outstanding communications tool, design patterns help make the design process faster. This allows solution providers to take the time to concentrate on the business implementation. More importantly, patterns help formalize the design to make it reusable. Reusability not only applies to the components themselves, but also to the stages the design must go through to morph itself into the final solution. The ability to apply a patterned repeatable solution is worth the little time spent learning formal patterns, or to even formalize your own. This entry looks at how architectural design considerations associated to BizTalk Server regarding messaging and orchestration can be applied using patterns, across all industries. The aim is to provide a technical deep-dive using BizTalk Server anchored examples to demonstrate best practices and patterns regarding parallel processing, and correlation.

The blog entry http://blogs.msdn.com/b/quocbui/archive/2009/10/16/biztalk-patterns-the-parallel-shape.aspx examines a classic example of parallel execution. It is consists of de-batching a large message file into smaller files, apply child business process executions on each of the smaller files, and then aggregating all the results into a single large result. Each subset (small file) represents an independent unit of work that does not rely or relate to other subsets, except that it belongs to the same batch (large message). Eventually each child process (the independent unit of work) will return a result message that will be collected with other results, into a collated response message to be leveraged for further processing.

This pattern is a relatively common requirement by clients and systems that interact with BizTalk Server, where a batch is sent in and they require a batch response with the success/failure result for each message. With this pattern one can still leverage the multithreaded nature of BizTalk’s batch disassembly while still conforming to requirement of the client.

Let’s closely examine how this example works. First, it uses several capabilities of BizTalk that are natively provided – some that are well documented, and some that are not. A relatively under-utilized feature – that BizTalk Server natively provides, is the ability to de-batch a message (file splitting) from its Receive pipeline. BizTalk Server can take a large message with any number of child records (which are not dependent with one another, except for the fact that they all belong to the same batch), and split out the child records to become independent messages for a child business process to act on. This child business process can be anything – such as a BizTalk Orchestration function, or a Windows Workflow.

BizTalk Server uses the concept of envelopes, which are BizTalk Schemas to define the parent and child data structures. These schemas are then referenced in a custom receive pipeline’s disassembler properties. This capability works on both XML and Flat file type messages.
Two schema envelopes (a parent and a child) are normally required to instruct BizTalk Server on how to split the file. However, using one schema is also possible.

To learn how to split a large file (also known as as de-batching) into smaller files, please refer to the BizTalk Server 2006 samples – Split File Pipeline example. Even though the sample is based on BizTalk Server 2006 (R1) – it remains relevant for BizTalk Server 2006 R2, BizTalk Server 2009, and BizTalk Server 2010.
Note: There are several examples on how to de-batch messages, such as de-batching from SQL Server, as communicated on Rahul Garg’s blog on de-batching.

After the large file has been split into smaller child record messages, child business processes can simultaneously work on each of these smaller files, which will eventually create child result messages. These child result messages can then be picked up by BizTalk Server and published to the BizTalk MessageBox database.

Once the messages are placed into the MessageBox database, they can be moved into a temporary repository, such as a SQL Server database table.
Messages collected into the database repository, can be collated, and even sorted by a particular identifier, such as the parent (the original large batched message) GUID.

To aggregate the results back to the same batch, correlation has to be used. BizTalk Orchestration provides the ability to correlate. Aggregation with Orchestration is relatively easy to develop. Using Orchestration, however, may require more hardware resources (memory, CPU) than necessary. One Orchestration instantiation will be required per batch (so if there’s 1000 large batch messages, then there will be 1000 Orchestration instances). Orchestrations linger until the last result message has arrived (or it can time out from a planned exception handling). There is an alternative way to aggregate, without Orchestration, but correlation is still necessary and required to collate all the results into the same batch. The trick is to correlate the result messages without Orchestration.

Let’s examine how correlation without Orchestration can be achieved.

Paolo Salvatori, in his first blog entry http://blogs.msdn.com/paolos/archive/2008/07/21/msdn-blogs.aspx describes how to correlate without Orchestration, by using a two-way receive port. This is important to note, because the two-way receive port provides key information that can be leveraged, by promoting them to the context property bag.

These key properties are

  • EpmRRCorrelationID
  • ReqRespTransmitPipelineID
  • IsRequestResponse
  • Correlation Token
  • RouteDirectToTP

Correlation without Orchestration is as easy as just promoting the right information to the context property bag. Of course, this information needs to be persisted, maintained, and returned with the result messages. However, this method only works with a two-way receive port. What about from a one-way receive port, such as from a file directory or MSMQ?

That is still possible because the de-batching (file splitting) mechanism of BizTalk Server provides a different set of compound key properties that can be used.

These are

  • Seq# (sequence number of child message)
  • UID (Identifier of parent message)
  • isLast? (Boolean whether if the child message is the last in the sequence)
 

The Sequence number of the child message, and the Boolean isLast can be used to determined the total number of records within the large message. For example, if there are 30 messages in a large message, the 30th message will have a sequence number of 30 (sequencing starts at 1), and isLast Boolean value of True.

 

 

The final step is to aggregate all the result messages and ensure that they’re correctly collated into the same batch that their original source messages from from. The UID that was used for correlation, is the parent identifier that can be used to group these result messages into. An external database table can be used to temporarily store the incoming messages, and a single SQL Stored Procedure can be used to extrapolate these messages into a single output file.

  • A result message is received by a FILE Receive Port
  • This result message is stored in a SQL Server table. This is achieved by being routed to a SQL Send Port where the original message is wrapped into a sort of envelope by a map which uses a custom XSLT. The outbound message is an Updategram which calls a stored procedure to insert the message into the table.
  • A SQL receive port calls a stored procedure to retrieve the records of a certain type from the custom table. This operation generates a single document.
  • This document is routed to a File Send Port where the message is eventually transformed into another format.

This method of using a SQL aggregator was communicated in http://geekswithblogs.net/asmith/archive/2005/06/06/42281.aspx

Note that the XSLT can be eventually replaced by a custom pipeline component or directly by an envelope (in this case the send pipeline needs to contain the Xml Assembler component).

Sample code is provided courtesy of Ji Young Lee, of Microsoft (South) Korea. Uncompress the ZIP file with the directory structure intact on the C:\ root directory (i.e.: c:\QuocProj). : http://code.msdn.microsoft.com/AsynchAggregation 

Acknowledgements to: Thiago Almeida (Datacom), Werner Van Huffel (Microsoft), Ji Young Lee (Microsoft), Paolo Salvatori (Microsoft)

Technorati Tags: BizTalk Server,Asynchronous,Aggregation,Large message processing,Split,De-batch,de-batching

ASP.NET Security Update Now Available

This morning Microsoft released a security update that addresses the ASP.NET Security Vulnerability that I’ve blogged about this past week.  We recommend installing it as soon as possible on your web-servers.

Common Questions/Answers

Below are some answers to a few common questions people have asked:

Do the updates require me to change any code?

No. The update should not require any code or configuration change to your existing ASP.NET applications.

Will I still need to use the workarounds after I install the update?

No. The update removes the need to use the security workarounds we’ve published this past week.  Those were temporary steps that could be taken to protect yourself before the update was released.  After you’ve installed the update you no longer need to use them. 

What is the impact of applying the update to a live web-server?

If you apply the update to a live web-server, there will be some period of time when the web-server will be offline (although an OS reboot should not be required). You’ll want to schedule and coordinate your updates appropriately.

Importantly – if your site or application is running across multiple web-servers in a web-farm, you’ll want to make sure the update is applied to all of the machines (and not just some of them). This is because the update changes the encryption/signing behavior of certain features in ASP.NET, and a mix of patched and un-patched servers will cause that encryption/signing behavior to be incompatible between them.  If you are using a web-farm topology, you might want to look at pulling half of the machines out of rotation, update them, and then swap the active and inactive machines (so that the updated machines are in rotation, and the non-updated ones are pulled from rotation and patched next) to avoid these mismatches.

Does this update work with SharePoint?

Yes.  We have not found any issues in testing SharePoint with this security update.  You should install it on SharePoint servers to ensure that they are not vulnerable.

Can I both install and uninstall the update?

Yes. The updates support install and uninstall scenarios.  Note that if you uninstall the update, though, it will leave your system unprotected.

Downloading the Updates

We are releasing the security update today via the Microsoft Download Center.  We will also release the update via Windows Update and the Windows Server Update Service in a few days as we complete final distribution testing via these channels. Once the update is on Windows Update, you can simply run Windows Update on your computer/server and Windows Update will automatically choose the right update to download/apply based on what you have installed.

If you download the updates directly from the Microsoft Download Center, then you need to manually select and download the appropriate updates.  Below is a table of all of the different update packages available via the Microsoft Download Center today. The downloads are split up by Windows Operating System (and corresponding service pack and processor architecture).  Each operating system version bucket below includes a listing of all available versions of .NET that are supported on it, and includes KB and download links to the appropriate security updates. 

Find your operating system within the below chart, then check to see which versions of .NET you have installed on it (details on how to determine which version of the .NET Framework is installed can be found here).  Download and apply the update packages for each version of .NET that you are using on that server.

Windows Server 2008 R2 and Windows 7

 

.NET Framework Version

KB Article

Patch

.NET Framework 3.5.1 (Default install)

KB2416471

Download

.NET Framework 4

KB2416472

Download

 

Windows Server 2008 SP2, Windows Vista SP2

 

.NET Framework Version

KB Article

Patch

.NET Framework 2.0 SP2 (default install)

KB2416470

Download

.NET Framework 4

KB2416472

Download

.NET Framework 3.5 SP1

KB2416470, KB2416473

Download, Download*

.NET Framework 3.5

KB2416470, KB2418240

Download, Download*

.NET Framework 1.1 SP1

KB2416447

Download

*When multiple patch downloads are listed above against a .NET version (for example with .NET 3.5 SP1 and .NET 3.5 installs) then all patches should be installed (order is not relevant).

Windows Server 2008, Windows Vista SP1

 

.NET Framework Version

KB Article

Patch

.NET Framework 2.0 SP1 (default install)

KB2416469

Download

.NET Framework 4

KB2416472

Download

.NET Framework 3.5 SP1

KB2416474, KB2416473

Download, Download*

.NET Framework 2.0 SP2

KB2416474

Download

.NET Framework 3.5

KB2416469, KB2418240

Download, Download*

.NET Framework 1.1 SP1

KB2416447

Download

*When multiple patch downloads are listed above against a .NET version (for example with .NET 3.5 SP1 and .NET 3.5 installs) then all patches should be installed (order is not relevant).

Windows Server 2003 SP2 32-bit

 

.NET Framework Version

KB Article

Patch

.NET Framework 1.1 SP1 (default install)

KB2416451

Download

.NET Framework 4

KB2416472

Download

.NET Framework 3.5 SP1

KB2418241, KB2416473

Download, Download*

.NET Framework 2.0 SP2

KB2418241

Download

.NET Framework 3.5

KB2416468, KB2418240

Download, Download*

*When multiple patch downloads are listed above against a .NET version (for example with .NET 3.5 SP1 and .NET 3.5 installs) then all patches should be installed (order is not relevant).

Windows Server 2003 64-bit

 

.NET Framework Version/SP

KB Article

Patch

Default OS Configuration

NA

NA

.NET Framework 4

KB2416472

Download

.NET Framework 3.5 SP1

KB2418241, KB2416473

Download, Download*

.NET Framework 2.0 SP2

KB2418241

Download

.NET Framework 3.5

KB2416468, KB2418240

Download, Download*

.NET Framework 1.1 SP1

KB2416447

Download

*When multiple patch downloads are listed above against a .NET version (for example with .NET 3.5 SP1 and .NET 3.5 installs) then all patches should be installed (order is not relevant).

Windows XP SP3 32-bit and 64-bit

 

.NET Framework Version/SP

KB Article

Patch

Default OS Configuration

NA

NA

.NET Framework 4

KB2416472

Download

.NET Framework 3.5 SP1

KB2418241, KB2416473

Download, Download*

.NET Framework 2.0 SP2

KB2418241

Download

.NET Framework 3.5

KB2416468, KB2418240

Download, Download*

.NET Framework 1.1 SP1

KB2416447

Download

*When multiple patch downloads are listed above against a .NET version (for example with .NET 3.5 SP1 and .NET 3.5 installs) then all patches should be installed (order is not relevant).

Summary

We recommend immediately applying the security update to your servers in order to protect your applications against attackers trying to exploit them.  We’d like to thank Juliano Rizzo and Thai Duong, who discovered that their previous research worked against ASP.NET, for not releasing their POET tool publicly before our update was ready.

You can ask questions and get help with the security vulnerability and update in a special ASP.NET Forum that we have setup here.  If you have problems or questions you can also contact Microsoft Customer Support for help (including support over the phone with a support engineer).  The official Microsoft Security Bulletin post is here.

Thanks,

Scott

Free e-book offer from Microsoft Press – Introducing Windows Server 2008 R2

Microsoft is offering a free e-book to partners. Learn about the features of Windows Server 2008 R2 in the areas of virtualization, management, the web application platform, scalability and reliability, and interoperability with Windows 7. Sign in to download Introducing Windows Server 2008 R2, written by industry experts Charlie Russel and Craig Zacker along with the Windows Server team at Microsoft.

Sign in to Microsoft Partner site to download the free e-book.

LOTS and LOTS of BizTalk Server 2010 Resources

This post is a follow-up to the RTM last week of BizTalk Server 2010. The BizTalk User Experience team has been REALLY busy putting together a ton of great resources. These are all live now, enjoy!

 

Learning:

  • BizTalk Server 2010 Training Kit
  • Video tutorials
  • Working with BizTalk AppFabric Connect

 

Documentation:

  • BizTalk Server 2010 Help
  • BizTalk RFID Server 2010 and BizTalk RFID Mobile 2010 Help
  • BizTalk Server 2010 ESB Toolkit Documentation
  • BizTalk Server Best Practices Analyzer
  • UDDI Help
  • BizTalk Server 2010 Management Pack Documentation
  • Windows Communication Foundation (WCF) Line of Business (LOB) Adapter SDK 2010 Documentation
  • BizTalk Adapter Pack 2010 Help
  • BizTalk Adapters 2010 for Enterprise Applications
  • BizTalk Accelerator for RosettaNet
  • BizTalk 2010 Accelerator for HL7 (BTAHL7) Documentation
  • BizTalk 2010 Accelerator for A4SWIFT
  • BizTalk 2010 FileAct and InterAct Adapters
  • Host Integration Server 2010 Help

 

Posters:

  • BizTalk Server 2010 Scale-out Configurations Poster
  • BizTalk Server 2010 Runtime Architecture Poster
  • BizTalk Server 2010 Capabilities Poster
  • BizTalk Server 2010 Database Infrastructure Poster
  • BizTalk Server 2010 BAM Poster
  • BizTalk Server 2010 ESB Toolkit Architecture Poster