Mapping Repeating Sequence Groups in BizTalk

Mapping Repeating Sequence Groups in BizTalk

Repeating sequence groups can often be seen in real life XML documents. It happens when certain sequence of elements repeats in the instance document. Here’s fairly abstract example of schema definition that contains sequence group:
<xs:schemaxmlns:b=http://schemas.microsoft.com/BizTalk/2003
xmlns:xs=http://www.w3.org/2001/XMLSchema
xmlns=NS-Schema1
targetNamespace=NS-Schema1 >
<xs:elementname=RepeatingSequenceGroups>
<xs:complexType>
<xs:sequencemaxOccurs=1minOccurs=“0”>
<xs:sequencemaxOccurs=unbounded>
<xs:elementname=Atype=xs:string />
<xs:elementname=Btype=xs:string />
<xs:elementname=Ctype=xs:stringminOccurs=0 />
</xs:sequence>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
And here’s corresponding XML instance document:
<ns0:RepeatingSequenceGroupsxmlns:ns0=NS-Schema1>
<A>A1</A>
<B>B1</B>
<C>C1</C>
<A>A2</A>
<B>B2</B>
<A>A3</A>
<B>B3</B>
<C>C3</C>
</ns0:RepeatingSequenceGroups>
As you can see elements A, B, and C are children of anonymous xs:sequence element which in turn can be repeated N times. Let’s say we need do simple mapping to the schema with similar structure but with different element names:
<ns0:Destinationxmlns:ns0=NS-Schema2>
<Alpha>A1</Alpha>
<Beta>B1</Beta>
<Gamma>C1</Gamma>
<Alpha>A2</Alpha>
<Beta>B2</Beta>
<Gamma>C2</Gamma>
</ns0:Destination>
The basic map for such typical task would look pretty straightforward:
If we test this map without any modification it will produce following result:
<ns0:Destinationxmlns:ns0=NS-Schema2>
<Alpha>A1</Alpha>
<Alpha>A2</Alpha>
<Alpha>A3</Alpha>
<Beta>B1</Beta>
<Beta>B2</Beta>
<Beta>B3</Beta>
<Gamma>C1</Gamma>
<Gamma>C3</Gamma>
</ns0:Destination>
The original order of the elements inside sequence is lost and that’s not what we want. Default behavior of the BizTalk 2009 and 2010 Map Editor is to generate compatible map with older versions that did not have ability to preserve sequence order. To enable this feature simply open map file (*.btm) in text/xml editor and find attribute PreserveSequenceOrder of the root <mapsource> element. Set its value to Yes and re-test the map:
<ns0:Destinationxmlns:ns0=NS-Schema2>
<Alpha>A1</Alpha>
<Beta>B1</Beta>
<Gamma>C1</Gamma>
<Alpha>A2</Alpha>
<Beta>B2</Beta>
<Alpha>A3</Alpha>
<Beta>B3</Beta>
<Gamma>C3</Gamma>
</ns0:Destination>
The result is as expected – all corresponding elements are in the same order as in the source document. Under the hood it is achieved by using one common xsl:for-each statement that pulls all elements in original order (rather than using individual for-each statement per element name in default mode) and xsl:if statements to test current element in the loop:
<xsl:templatematch=/s0:RepeatingSequenceGroups>
<ns0:Destination>
<xsl:for-eachselect=A|B|C>
<xsl:iftest=local-name()=’A’>
<Alpha>
<xsl:value-ofselect=./text() />
</Alpha>
</xsl:if>
<xsl:iftest=local-name()=’B’>
<Beta>
<xsl:value-ofselect=./text() />
</Beta>
</xsl:if>
<xsl:iftest=local-name()=’C’>
<Gamma>
<xsl:value-ofselect=./text() />
</Gamma>
</xsl:if>
</xsl:for-each>
</ns0:Destination>
</xsl:template>
BizTalk Map editor became smarter so learn and use this lesser known feature of XSLT 2.0 in your maps and XSL stylesheets.

Referring EDMX file in Separate VS Project from T4 Template

In my project I needed to separate template generated entities, context in separate projects from the EDMX file. I’ve stumbled across this problem how to make template generator to find edmx file without hardcoding absolute path into the template. Using relative path directly (inputFile=@”..\ProjectFolder\DataModel.edmx”) generated error:
Error 2 Running transformation: System.IO.DirectoryNotFoundException: Could not find a part of the path ‘C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\ProjectFolder\DataModel.edmx’
The code that worked well for me when placed in the beginning of the .tt file:
string rootPath = Host.ResolvePath(String.Empty);
string relativePath = @”..\\ProjectDir\\DataModel.edmx”;
string inputFile = Path.Combine(rootPath, relativePath);
EdmItemCollection ItemCollection = loader.CreateEdmItemCollection(inputFile);

BizTalk HL7 Receive Pipeline Exception

If you experience sequence of errors below with BizTalk HL7 MLLP receive ports you may need to request a hotfix from Microsoft. Knowledge base article number is 2454887 but it’s still not available on the KB site. The hotfix is recently released and you may need to open support ticket to get to it. It requires three other hotfixes installed:
%u00b7 970492 (DASM 3.7.502.2)
%u00b7 973909 (additional ACK codes)
%u00b7 981442 (Microsoft.solutions.btahl7.mllp.dll3.7.509.2)
If the exceptions below repeatedly appear in the event log you most likely would be helped by the hotfix:
Fatal error encountered in 2XDasm. Exception information is Cannot access a disposed object. Object name: ‘CEventingReadStream’.
There was a failure executing the receive pipeline: “BTAHL72XPipelines.BTAHL72XReceivePipeline, BTAHL72XPipelines, Version=1.3.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35” Source: “BTAHL7 2.X Disassembler” Receive Port: “ReceivePortName” URI: “IPAddress:portNumber” Reason: Cannot access a disposed object. Object name: ‘CEventingReadStream’.
The Messaging Engine received an error from transport adapter “MLLP” when notifying the adapter with the BatchComplete event. Reason “Object reference not set to an instance of an object.”
We’ve been through a lot of troubleshooting with Microsoft Product Support and they did a great job finding an issue and releasing a fix.

Off Topic-Payback is a .

Off Topic-Payback is a .

So you may recall a bet that took place around the 2010 Olympic timeframe which had me, and Team Canada, matched up against fellow BizTalk MVP Mikael H%u00e5kansson and Team Sweden.  As we all know, Canada won the Olympic Gold Medal and I won the bet.

The Christmas break is well anticipated holiday for many obvious reasons in Canada.  While most people in Canada are stuck indoors for the coldest part of the year, many are glued to their television sets watching the World Junior Hockey tournament.  This tournament represents the best under 20 year old Hockey players on the the planet.  Most of these players will end up playing professional Hockey somewhere and many will make the NHL.

On December 31st, 2010, Canada squared off against Team Sweden in a round robin game.  Once again Mikael taunted me with a blog post so I couldn’t resist opening up that wound of his from earlier in the year.

This time around it is my time to eat crow.  Sweden beat Canada 6-5 in a shoot-out and in return here is my tribute to Team Sweden and Mikael.

There are still some games left and I am confident that Team Canada can pull it off. There is a good chance that Canada could play Sweden so perhaps there will be a rematch bet?

friberg_73159

Microsoft MVP Awarded: Part 4

I recently received word that I have been re-awarded for another year.  Contributing to the BizTalk community continues to be something I enjoy and am passionate about so it is always nice to be recognized by Microsoft for my efforts.

Looking back at 2010, it sure was a busy year.  I spent a lot of time in the areas of SharePoint and SAP integration.  I attended TechEd in New Orleans where I also helped out at the BizTalk booth.  I gave a SharePoint and App Fabric Service Bus presentation to the Calgary .Net User group and had the opportunity to go to Sweden and speak about Monitoring your BizTalk environment with SCOM.  Travelling to Stockholm and spending time with Mikael H%u00e5kansson and Johan Hedberg was one of my highlights even if Mikael signed both Johan and I up for an Olympic distance triathlon.

2011 is shaping up to being just as busy if not busier than 2010.  Here are some of the things coming up for me:

  • I am currently the Integration Architect on a Dynamics CRM/Project Server 2010/SharePoint 2010/SAP project so I will continue to be very involved with integrating line of business systems.  Expect more SAP and Dynamics CRM content on this blog.  I am thinking about building a series around CRM 4.0  integration much like the ShareTalk series that I previously published on this site.
  • Speaking of Line of Business systems, the rumor is true.  I have teamed up with a group of really talented authors to write a BizTalk book.  The book will be unlike any of the current BizTalk books and will target experienced BizTalk developers.  The list of authors and technical reviewers is impressive, I am very confident that the end product will be great.  More information will be forthcoming, but you can expect the book to be available towards the end of April 2011.
  • Learning more about AppFabric is also on my “resolution” list for 2011.  While I have a very good idea of what AppFabric is and what you can do with it, I just haven’t had a lot of “hands on” experience with it.
  • While unrelated to this blog, I just love my Windows Phone 7 device and have previously written the “BizTweet” app for it.  I look to expand my skills in this area as well.  I have a couple ideas that I plan on pursuing, one that does involve BizTalk and SAP.

While no where near Seroter numbers, this blog received just over 40 000 hits over the past year, so I thank you for taking the time to stop by and read my content.  All the best for the upcoming year.

BizTalk Server MVP 2011

BizTalk Server MVP 2011

Since two years I am getting a great news of being Microsoft’s Most Valuable professional (MVP) on the new year. I thank my peers, community members, fellow MVPs, MVP Lead and Microsoft which honored me and recognized my contributions in BizTalk communities. Last year I gained knowledge, experience and more insight in BizTalk which includes […]

Links to my “Best of 2010” Posts

I hope everyone is having a Happy New Years!

2010 has been a busy blogging year for me (this is the 100th blog post I’ve done in 2010).  Several people this week suggested I put together a summary post listing/organizing my favorite posts from the year. 

Below is a quick listing of some of my favorite posts organized by topic area:

VS 2010 and .NET 4

Below is a series of posts I wrote (some in late 2009) about the VS 2010 and .NET 4 (including ASP.NET 4 and WPF 4) release we shipped in April:

Visual Studio

Below are some additional Visual Studio posts I’ve done (not in the first series above) that I thought were nice:

Silverlight

We shipped Silverlight 4 in April, and announced Silverlight 5 the beginning of December:

Silverlight for Windows Phone 7

We shipped Windows Phone 7 this fall and shipped free Visual Studio development tools with great Silverlight and XNA support in September:

ASP.NET MVC

We shipped ASP.NET MVC 2 in March, and started previewing ASP.NET MVC 3 this summer.  ASP.NET MVC 3 will RTM in less than 2 weeks from today:

IIS and Web Server Stack

The IIS and Web Stack teams have made a bunch of great improvements to the core web server this year:

EF Code First

EF Code First is a really nice new data option that enables a very clean code-oriented data workflow:

jQuery and AJAX Contributions

My team began making some significant source code contributions to the jQuery project this year:

Patches and Hot Fixes

Some useful fixes you can download prior to VS 2010 SP1:

Videos of My Talks

Some recordings of technical talks I’ve done this year:

Other

I’d like to say a big thank you to everyone who follows my blog – I really appreciate you reading it (the comments you post help encourage me to write it). 

See you in the New Year!

Scott

P.S. In addition to blogging, I am also now using Twitter for quick updates and to share links. Follow me at: twitter.com/scottgu

Enabling Network discovery in Windows Server 2008 R2

I have been configuring servers lately and have come across an issue that wasn’t clear.

I needed to enable network discovery, so I simply went to the advanced sharing center

I was unable to keep the sharing active.

I realized that I needed to ensure that the following services were running:

  • Function Discovery Resource Publication
    SSDP Discovery
    UPnP Device Host

Also, I wanted to see ping requests, so I enabled the following in the Advanced Firewall settings:

Winner of the Best Missing Feature in BizTalk 2010 is?

I just wanted to thank all the entries into the “What is missing in BizTalk 2010 Contest”.  It was a hard decision for the other judges and I.

Finally, the decision was made.  The winner was Siffnn from the UK.  He received a free hard copy of my book “Applied Architecture Patterns on the Microsoft Platform”.

His entry was the following:

“I Would like to See following features :

1- GUI in admin console to tune BizTalk Message Box Parameters

2- GUI similar to SQL Management studio to gather performance stats report for BizTalk Hosts/SQL Databases.

3-Web Based Fast Admin Console,tool.

4- Debugging Options should be easy

5- Standard Application Logging/Caching framework

6-Messaging Patterns should be available in Visual Studio while creating a BizTalk Project

7-There should be standard templates available to add performance counters in PUB/SUB projects.

8-There should be GUI tools available on BAM Infrastructure.

9-BAM Portal should be modified to display larger volume of data using custom data grids. Currently available reports are not very fast.”

Again, thanks to everyone who entered! 

Have a Happy New Year!

2010 Year in Review

2010 Year in Review

I learned a lot this year and I thought I’d take a moment to share some of my favorite blog posts, books and newly discovered blogs. Besides continuing to play with BizTalk Server, I also dug deep into Windows Server AppFabric, Microsoft StreamInsight, Windows Azure, Salesforce.com, Amazon AWS, Microsoft Dynamics CRM and enterprise architecture. I […]