Processing FIFO MSMQ Messages using WCF

 

I have been having fun working on the middle tier of an application which is using BizTalk, Windows Workflow, MSMQ and the Windows Communication Framework.


 


One of the requirements is to processes messages we receive from a legacy system through MSMQ in FIFO order. 


 


We used WCF to communicate with MSMQ and used the msmqIntegrationBinding binding since the legacy application was placing the messages on the queue.


 


The FIFO processing seemed to be little more difficult to iron out.  It turns out that by default a service’s InstanceContextMode is PerSession.  If the channel is a datagram then the IntanceContextMode degrades to PerCall.  So what happens is that the WCF runtime will create a new service instance for each available request/message up to the MaxConcurrentCalls/MaxConcurrentInstance setting utilizing multiple threads.  This was not going to provide my FIFO processing.


 


So, to set WCF to only pull and process one message at a time you need to set the service’s InstanceContextMode to Single along with setting the ConcurrencyMode to single.  The following code shows these settings:


 


        [ServiceBehavior(InstanceContextMode = InstanceContextMode.Single,


        ConcurrencyMode = ConcurrencyMode.Single,


         )]


    public class MSMQEventService : IMSMQEventInterface, IDisposable


    {


 


Once these settings are set you will achieve FIFO processing and WCF will only utilize a single thread and will process one message at a time from the single queue.


 


My next entry will cover processing multiple queues and processing each queue in FIFO order. 

BizTalk R2 Training Australia – October 2007

Email from our internal readiness team…

 

Hi,

Aligned to the BizTalk Release 2, global launch in Australia, we have scheduled the training for Partners as per below.

Please ensure that your partners are aware of this and register: As always – thank you very much.

 

BizTalk R2

https://www.local.microsoft.com.au/australia/events/register/home.aspx?levent=478264&linvitation

Sydney – Oct 18 & 19

Brisbane – Oct 15 & 16

Melbourne – Oct 25 & 26

Perth – Oct 18 & 19

DebugView and the elusive ‘Capture Global Win32’ option

Like most BizTalk Server developers I am addicted to the use of DebugView. This, in case you are one of the three BizTalk developers out there who are still not aware of it, is a free utility written by the SysInternals people. Microsoft bought SysInternals a while back, and the utility can now be downloaded from their web site at:
http://www.microsoft.com/technet/sysinternals/utilities/debugview.mspx
DebugView provides a viewer for traces created using the Win32 OutputDebugString() API.You can liberally instrument your .NET code using calls to System.Diagnostics.Debug.Write<xxx> methods, then open up DebugView and run you code. The output is nicely displayed in the DebugView console.For BizTalk developers, this is an indispensable tool because there is no way to single-step through XLANG/s expressions. The Orchestration debugger is built on top of the orchestration engine, and is not a ‘true’ Win32 debugger. It can only single-step through interactions between the orchestration and the orchestration engine which occur at a much coarser level of granularity than individual lines of XLANG/s code.
I’ve spent the last couple of weeks pretending to be an ASP.NET 2.0 developer. The code I was writing does a fair amount of re-direction. It supports a number of different log-in models based on the Forms Authentication model in ASP.NET 2.0, but integrated with a remote identity provider. The code is ‘proof of concept’ stuff, and supports different ’candidate’ approaches, including the ability to switch to local authentication in order to demonstrate the code in scenarios where we have no remote connectivity. To begin with I (rather stupidly, in hindsight) was trying to develop using the new Web Site project type in Visual Studio. Oh dear. I needed to use SSL sessions to debug the code because we are using CardSpace. You can’t do this under the local web server. I tried, without success, to debug my code under IIS, but found that, for some reason, I was unable to attach to IIS worker processes! Then, I really came unstuck when ASP.NET completely lost the ability to debug. It was creating pdb files OK, but one of them appeared to be corrupted somehow each time it was built (for example, no version number), and Visual Studio insisted that I had no symbols loaded, even though the Module window clearly showed that I did!
I gave up, and ported the code over to a Web Application project. I still have problems. Visual Studio currently reports a set of spurious build errors ‘dynamically’ while using the designer (these change dynamically over time even if I don’t touch the keyboard – yes I mean it!I just sit there and stare at the screen for a minute or two and see the error messages change before my eyes), but then builds and publishes the application anyway. It has lost the ability to see Master Pages if I use generated paths with the ‘~’ specifier.It has also become hopelessly confused in regard to a custom control that I am using -a problem, incidentally, for which there are thousands of hits in Google, but only one conclusion – ‘tough – it’s a long-standing bug – you can’t fix it and there’s no known workaround – rebuild your project from scratch’. Apart from that, the Web Application works OK, and I can now debug my code smoothly under SSL sessions. A good lesson learned. I certainly won’t use Web Site projects in future, and will try not to use ASP.NET unless I have to, until such time as Microsoft sees fit to stabilise the design-time ASP.NET tools.
The point of this, apart from letting off steam about the general flakiness of ASP.NET 2.0 under Visual Studio 2005 SP1 (it’s horrible), is that while developing using the Web Site, I needed to use DebugView quite extensively. Even now, it is of some use due to the re-direction. I can trace my code in one page, even though this page redirects to another so that I can’t see my trace output using the built-in tracing features of ASP.NET. DebugView shows me what I need to see, as long as I remember to place ‘#define DEBUG’ statements in my ‘CodeBehind’ files.
I ran into a problem with DebugView which I have seen before. I’ve been trying to research it to come up with a definitive answer, but I don’t know the underlying cause – just the symptoms. My problem is that my ASP.NET code runs in a different session to the desktop. This means that the output does not appear in DebugView unless I enable the ‘Capture Global Win32’ option. However, this option was not available in DebugView.
At this point, I should say that I am developing on Windows Server 2003 R2. I run Vista on my notebook. When I open the same version of DebugView on my Vista notebook, I can see the ‘Capture Global Win32’ option. However, I can’t see it when I run DebugView on the Windows Server 2003 box.
I was tearing my hair out over this one, and it isn’t the first time I have run into this problem. I spent some time trying to find an answer on Google. I didn’t turn anything up, but somewhere I read something about remote connections. I had a thought. I powered up a Remote Desktop session to my own development box and then opened DebugView. Success! The ‘Capture Global Win32’ option appeared, and once selected, DebugView started happily displaying the output from my ASP.NET application.
This approach cannot be used on XP (or, I think, Vista) because, even with SP2, XP does not support concurrent remotedesktop sessions. Apparently, Microsoft was going to lift this restriction at some point, but then decided not to. As I say, when running DebugView under Vista, I don’t get the problem anyway.
I experimented further with DebugView by setting up a ‘client’ instance (surely this should be termed a ‘server’ instance’) and then connecting to this on the same machine. In my first attempt, this appeared to work, but when I tried to reproduce the approach the following day, it failed. The Remote Desktop approach works every time though.
As I say, I don’t currently have an explanation. I know, from Googling, that there are some interesting issues when using OutputDebugString regarding the permission set granted to an underlying Mutex. Maybe the behaviour of DebugView has something to do with this. Maybe the explanation is simpler. It may have something to do with having another registered debugger in the same Windows session. I’m not sure. What I do know is that remoting into your own desktop on Windows Server 2003 works very nicely indeed.

MS BRE: State Transition Pattern

My fellow BizTalk MVP, Leonid Ganeline, asked if I would comment further on mechanisms to govern sequential flow in rules in MS BRE. He was picking up on some comments I made in my article comparing WF and MS BRE rule performance (see http://geekswithblogs.net/cyoung/archive/2007/08/12/114597.aspx#143628).
What I had in mind was the use of state transition patterns within rule sets. These can be used to layer a degree of sequential control over the set-based pattern matching approach taken by engines like MS BRE. The basic pattern is simplicity itself, and very common. What I generally do is assert an additional ‘context’ fact to the engine (typically some custom .NET object) in which I maintain a state specifier (e.g., a simple string property). I can then group rules together to match specific states, and use a low-priority rule in each group to change the state. The ‘sequential’ flow is then governed by the state transitions. Of course, any single group of rules that match the same state do not operate in a sequential fashion amongst themselves. However, you can always just have one main rule per state if you wish. Here is a very, very simple example of the kind of pattern I have in mind.

/*********************************************
* Group 1 – ‘Started’ state
********************************************/

Rule 1
IF
AND
Context.CurrentState == “started”
MyFactA.Property1 > 5
MyFactB.Property1 < MyFactA.Property
THEN
MyFactB.Property1 = MyFactA.Property1
assert MyFactB

Rule 2 (priority -1)
IF
Context.CurrentState == “started”
THEN
Context.CurrentState = “initialised”
assert Context

/*********************************************
* Group 2 – ‘Initialised ‘ state
********************************************/

Rule 3
IF
AND
Context.CurrentState == “initialised”
MyFactA.Property2 == “USA”
THEN
MyFactA.SetCountryCode(“01”)

Rule 4
IF
AND
Context.CurrentState == “initialised”
MyFactA.Property2 == “UK”
THEN
MyFactA.SetCountryCode(“44”)

Rule 5 (priority -1)
IF
Context.CurrentState == “initialised”
THEN
Context.CurrentState = “completed”
assert Context
assert MyFactA // convenient place to re-assert MyFactA
//to avoid loops if, for example,
// MyFactA.SetCountryCode() changes the
// state of MyFactA.

/*********************************************
* Group 3 – ‘Completed’ state
********************************************/

Rule 6
IF
AND
Context.CurrentState == ” completed “
THEN
MyFactA.Property1 = 0
MyFactB.Property1 = 0

/********************************************/

The low-priority ’state transition’ rules are rules 2 and 5. Group 2 contains two main rules, whereas the other groups have just one main rule.
Personally, I think MS BRL (and the Rules Composer) should provide a built-in abstraction for this design pattern – i.e., provide a way of grouping rules by state, and declaring how to transition to a new state when a group has completed its work. If this was supported, it would not be necessary to explicitly define an additional low-priority rule in each group.
This design pattern can be a little difficult to maintain in MS BRE currently because the rule composer displays rules in alphabetic order in the UI, regardless of the order in which you created them, and so you cannot see the groupings and state transitions. The answer to this, of course, is to adopt a rule naming convention which makes the pattern more explicit in the UI.
I used this design pattern recently when creating a rule set for applying Bayes Theorem. See http://geekswithblogs.net/cyoung/archive/2007/08/27/114988.aspx. The rule set was written for other rule engines (Jess and CLIPS), but uses exactly the same principle. I have ported the rule set to MS BRE, but just need to clear a potential commercial hurdle before publishing the code.

BizTalk 2006 R2 Launch in Sydney – recap

BizTalk 2006 R2 Launch in Sydney – recap

What a great event – BizTalk, BizTalk and more Biztalk.

It was great to see all those who attended and especially those from the user groups
(Sydney, Brisbane and Melb)

I personally had a great day – the weather was great. It was sunny, it hailed and
then in true fashion the sun was out again.

So this means that BizTalk 2006 R2 is now RTM – grab it from here

Scott (another BizTalk super hero) & I put together a great RFID Demo (I can say
*great* being not too bias).

Come 2am the morning before the launch Scott & I were wondering ‘was there going
to be a demo?’. In true show style it all came off on the day 🙂
I’ll blog about the demo shortly….it went down a treat

There were some great sessions (I wasn’t able to get to them as I was a ‘booth babe’
for the day).

The thing that I was most impressed about on the day……was the amount of
support from the Corp BizTalk team. Well done guys!!! smile_regular

The team had been on the road launching R2 in 3 world wide locations (in
Taipei they were treated almost like rock star status!).

We had Oliver Sharp (BizTalk PM) and major figures in his team – the guys were great
and always willing to lend an ear. (Some of them were off surfing at
Bondi the following day – that’s the way it’s done !! 🙂

In mentioning the team I can’t fail to mention MR. RFID of MS – Anush Kumar. What
a great genuine guy. He’s always got a brilliant story to tell around Microsoft
RFID Services. RFID, Integration, surfacing, WCF, BizTalk, BAM, TagEvent data – these
are all words he uses. This is a huge Microsoft story – and what the RFID team has
achieved it the last 3-4 years both on the hardware/software space is amazing. Standardising
readers (c.f. ODBC and ODBC drivers) and providing momentum to standards bodies on
various tags and their formats.

R2 here we come….time to update some VPCs.

As promised to many here are my links from recent presentations

Links from my recent Mashup the Web presentations…

All Blacks Silverlight Gadget

HD View

Photosynth – Nasa

Live local

Contoso Bike Club

Silverlight Space Invaders

Image Search (filter:face)

Tafiti

BackgroundMotion

Popfly

Silverlight Streaming

Zero Gravity

LCI

Media Preview

Terra TV

French Rugby

Demo Applications…

Evermore Reflection Video – Silverlight 1.0

Trex 3D – WPF

Silverlight Surface

News Feeds…

VisitMix

SilverlightCream

Arturo

Scott at MIX UK

Shane – Wireframing in Blend – Starter Project

Aussie Remix videos

Expression Encoder…

Clarkezone

Custom Templates

Community…

If you are lucky enough to live in Wellington Nas has set up a user group for designers called http://zamdes.com. The Expression team at Microsoft is also kicking off a global design event in Auckland on the 4th of October called “Expression around the Clock”. Places are limited but please spread the word and register at http://www.microsoft.co.nz/expression for the free half day Auckland event otherwise follow along on the global website http://expressionevent.com.

If you haven’t already please subscribe to the Microsoft Designer UX newsletter that we will start sending out once a month. You can subscribe by visiting http://tinyurl.com/2uwnpe and filling in the email template.

MS-HUG Day 1

Wanted to recap the list of things I walked away with today from the conference at MS-HUG:

Keynote address

Bill Crounse, MD, Director Worldwide Health Microsoft Corporation

Well, I got to listen to Bill (no not that Bill) and it was interesting, I learned today that CMS will significantly curtail the payments of procedures for in hospital infections. This will have rippling effects for the providers, and will spurn the pay for performance initiatives and quality of care initiatives as hospitals will now have to foot the bill for those issues.

Winning Trust, Minimizing IT Resources: Key to Forming RHIOs

Mark Singh President Clinicore Solutions

Kathleen Sullivan CEO Salient Health Solutions/SEMRHIO Consultant

Being the architect I am very much aware of what is going on (I had better!), however it was interesting because most of the questions were focused on the business model, the revenue generation process. This is the next phase in our process, but having a working process in place I feel is the key to success as we now have 3 hospitals up with minimal IT resources.

Reference Implementations for Healthcare: HCE and iHE XDS.b(sorry the link does not work as of yet)

Roberto Ruggeri Senior Technical Strategist for Microsoft Worldwide Health Microsoft Corporation

Randy Fusco Technical Strategist for Microsoft US Health Providers Microsoft Corporation

This was a great presentation where I learned about how much Microsoft is looking for us to help. For those who write blogs and to those who read blogs (you know who you are) it was a call to action! Yes you!

On http://solshare.net you can download the code and start to try it out and using their forum, you can submit bugs, ask for enhancements, etc.

I asked if there was a list of known issues, in which Roberto told me that no, this was a feature, that we get to start our own list and he will see if we really know what we are doing! (j/k) Seriously, he said that there is no existing list of issues, so I would assume that you can post those known issues/fixes directly on the solshare.net site.

Lunch

I went out to eat with Eric Battalio, Muhammad, and Liza from the documentation team, and wow, I learned a lot! The first and most important thingI learned is that those comments that you can leave on the documentation site actually go to someone. My suggestion is that if you want to start a dialog with the documentation team (which by the way, they would LOVE), it would be nice to have some type of post submission question asking if you (the feedbacker) would like to be contacted by Microsoft and what email they can contact you.

In the interim, just put your email address in the comments so they can contact you directly, Iassume that there will be something in the worksaddressing this issue.Below is an example of something I have had on the back of my mind recently.

Improving Patient Safety Using the Microsoft Common User Interface (MS-CUI)

Andrew Kirby Director of Solutions Development Center Microsoft Corporation, UK

Like the CHF, this is very much a work in progress and since it is very early on in the development, it is more of a guideline and they need as much feedback as possible. However there are no immediate plans for a reference implementation to build off of other than the first implementation in England.

What’s New in BizTalk Server 2006 R2

Stuart Landrum Program Manager, BizTalk, Microsoft Corporation

Well, it was the first time I had met Stuart face to face, had been on some conference calls with him, so it was good to meet him. He explained the new features with the HL7 accelerator (now officially branded 2.0). There was very little pictures of the product so the discussion went rather quickly and ended early with few questions, I had to ask a few questions to get people in the asking mood, but it did not go much further than that.

Closing Keynote: Using IT to affect efficiency and safety changes in the erioperative process

Conclusion

Paul St. Jacques, MD Associate professor and Director of Perioperative informatics Vanderbilt University

This doctor was actually kind of funny. I am not sure if he meant to be, but if it was not for his phones (yes plural) that added a little static to his voice, or his low ranking on the pay for performance ratings that he refuse to show on the list of many doctors ranked (it was too small to see), it was a good presentation that ended on a high note, even though he essentially had to ask us to laugh, even though there wasn’t really anything funny about his presentation. He did use one of my all time favorite phrases, while describing the hospital system that he works in, he described it as a level 1 trauma facility that is “soup-to-nuts” – where did that come from and should we be saying that phrase as professionals?

The interesting thing that I thought that he was going to joke about was his workflow from a patient pre-registration process through surgery completion. look closely for anything wrong with this picture

nope, not the fact that they are using SQL Server 2003 (must be a special version of SQL Serverthat I am notaware of)

The real problem with this picture is that there is a little girl that starts the surgery process, and when the workflow is complete, thegirlis actuallyHenry Kissinger! Either that process took a really long time (and something major wrong happened), or this is a plastic surgeon’s billing dream come true!

Talk to you all tomorrow!

My BizTalk vNext Wish List

Congrats to the Connected Systems Division for getting BizTalk Server 2006 R2 out the door. Now that we’re done with that, here’s my humble “wish list” for BizTalk Server vNext. I realize that development is well under way, but, hopefully some of these requests can make it in.

Design Tools

High level modeling tool. Nothing […]