Mapping from multiple source document with a key

In my last blog post I said that when I found more scenarios that required custom XSLT I would blog about it.  I just didn’t think it would be quite so soon. 


 


In this case I have two source documents and I needed to loop through one of them and select items off the other and map elements from both source documents to the destination document.  I am working on this project with Matt Cable (who works for Quilogy and is in the Virtual TS for BizTalk program) and he showed me a great way to accomplish this (he looked over my shoulder as I was trying to figure something out and said it would be much easier to do it this way.  I am very glad too because as I look back,  what I was putting together was far more difficult).


 


So I have these two source documents (as shown in the screen shot below) and I need to loop through the bottom message and for every VendorUPC I need to match that up with the upper document and pull the Image and ImageThumb elements (it is not expanded in the screen shot but under the Color element there is a sku attribute that I can match up with the VendorUPC)


 



 


The following is what the XSLT looks like.  We setup a for each loop around the bottom message at the record level.  The ItemNumber and VendorUPC elements were easy as we could just take those from the current position in the loop.  We were equally lucky with the URL element since it was not a repeating element and therefore we could grab that value.


 


The Image and ImageThumb is where it gets interesting.  This is where we need to take the VendorUPC from the bottom document and match it up to the sku attribute in the top document and map the value.  This is done through the code in the highlighted section.  Everything in between the open and close brackets acts like a where clause.  For this schema, the sku apears at a lower level in the hierarchy then the actual data that I needed to map.  So in this case I am saying that at the xslt processor should look at /Color/Size/sku where that sku matches the current iterations VendorUPC.  If there is a match then pick the /Color/pic_standard or /Color/pic_thumb attribute  value and map that to the destination.


 


<xsl:for-each select=”/*[local-name()=’Root’ and namespace-uri()=’http://schemas.microsoft.com/BizTalk/2003/aggschema’]/*[local-name()=’InputMessagePart_1′ and namespace-uri()=”]/*[local-name()=’MissingVendorImagesResponse’ and namespace-uri()=’http://MissingVendorImages’]/*[local-name()=’XXXXX_CatalogProducts’ and namespace-uri()=’http://MissingVendorImages’]”>


 


<ImageData>


<ItemNumber>


<xsl:value-of select=”@ItemNo”/>


</ItemNumber>


<URL>


<xsl:value-of select=”/*[local-name()=’Root’ and namespace-uri()=’http://schemas.microsoft.com/BizTalk/2003/aggschema’]/*[local-name()=’InputMessagePart_0′ and namespace-uri()=”]/*[local-name()=’ProductList’ and namespace-uri()=”]/@pic_url_prefix”/>


</URL>


<Image>


<xsl:value-of select=”/*[local-name()=’Root’ and namespace-uri()=’http://schemas.microsoft.com/BizTalk/2003/aggschema’]/*[local-name()=’InputMessagePart_0′ and namespace-uri()=”]/*[local-name()=’ProductList’ and namespace-uri()=”]/*[local-name()=’CatalogSection’ and namespace-uri()=”]/*[local-name()=’Model’ and namespace-uri()=”]/*[local-name()=’ColorVariations’ and namespace-uri()=”]/Color[Size/@sku = current()/@VendorUPC]/@pic_standard”/>


</Image>


<ImageThumb>


<xsl:value-of select=”/*[local-name()=’Root’ and namespace-uri()=’http://schemas.microsoft.com/BizTalk/2003/aggschema’]/*[local-name()=’InputMessagePart_0′ and namespace-uri()=”]/*[local-name()=’ProductList’ and namespace-uri()=”]/*[local-name()=’CatalogSection’ and namespace-uri()=”]/*[local-name()=’Model’ and namespace-uri()=”]/*[local-name()=’ColorVariations’ and namespace-uri()=”]/Color[Size/@sku = current()/@VendorUPC]/@pic_thumb”/>


</ImageThumb>


<VendorUPC>


<xsl:value-of select=”@VendorUPC”/>


</VendorUPC>                


</ImageData>


</xsl:for-each>


 


 


 


 

XSLT and a Commerce Server Catalog Query

I am becoming more and more convinced that you need to have good XSLT skills to work with the Commerce Server Adapters for BizTalk.  Well, I came across a situation that called for a custom XSLT solution.  I have written about some of these cases in past blog entries and as I find more situations I will add blog entries.


 


In this case, I needed to download images from a third party site for products in our catalog that were missing images.   I needed to query Commerce Server and pass in a list of items that I wanted to return.  In this case it was based on the VendorUPC element (as shown in the screen shot below).


 


 


 


 


 I needed to create the query so that it would look like:


 


<CommerceServerCatalogQuery ProductCatalog=”Images” SearchClause=”VendorUPC=’100′ Or VendorUPC=’101′ Or VendorUPC=’102′”></CommerceServerCatalogQuery>


 


So, the issue was how do I append all of the VendorUPC elements to create the SearchClause.  This is where the custom XSLT comes in.


 


Here is the XSLT that produces the above xml output.


 


<xsl:attribute name=”SearchClause”>


                <xsl:variable name=”ItemCount” select=”count(/*[local-name()=’Root’ and namespace-uri()=’http://Ecommerce.Schemas.ImageDownloadData’]/ImageData)” />


                <xsl:choose>


                                <xsl:when test=”$ItemCount = 0″></xsl:when>


                                <xsl:when test=”$ItemCount = 1″>VendorUPC='<xsl:value-of select=”/*[local-name()=’Root’ and namespace-uri()=’http://Ecommerce.Schemas.ImageDownloadData’]/ImageData[1]/VendorUPC” />'</xsl:when>


                                <xsl:otherwise>VendorUPC='<xsl:value-of select=”/*[local-name()=’Root’ and namespace-uri()=’http://Ecommerce.Schemas.ImageDownloadData’]/ImageData[1]/VendorUPC” />’


                                <xsl:for-each select=”/*[local-name()=’Root’ and namespace-uri()=’1″>http://Ecommerce.Schemas.ImageDownloadData’]/ImageData[position()>1]”> Or VendorUPC='<xsl:value-of select=”VendorUPC” />’


                                </xsl:for-each></xsl:otherwise>


                </xsl:choose>


</xsl:attribute>


 


This can be used any time you need to iterate over a repeating source structure and either ‘Or’ or ‘And’ values together in a single output element.

MIX07 Your Product is a feature of the Web!

It is now Sunday the 6th of May and I want to do my MIX wrap before I return to the office on Monday morning. Well Wednesday isn’t too bad 😉


First of all I just want to say “Wow”… last year MIX put a line in the sand marking Microsoft’s strengthening commitment to the Web… this year we built on it in a big way with Silverlight’s coming out party!


It was awesome to have User Experience, Design and Development represented so well at one conference and NEVER before at a Microsoft conference have I seen Mac’s on stage in keynotes, used in ~ 1/4 of the sessions and available for attendees to drive themselves in the hands on labs.


The day 1 keynote featured Scott Guthrie. Scott pulled out Visual Studio and doing what he does best showed edit and continue debugging a Silverlight 1.1 application running on a Mac! Does anyone remember Scott’s Silverlight (WPF/E) Vegas dice demo from Tech.Ed in Auckland last August? Well we’ve come a long way since then!


What was Scott Guthrie’s comment during last weeks keynote?


“Now, not only do we support running applications on the Mac, we also support debugging the applications on the Mac. So, for example, we’ll go here in Visual Studio now, and one of the things you can see that’s kind of cool is we have a feature called Attach to Process. And you’ll notice we now have a new option here called CLR Remote Cross Platform Debugging. You can tell that a dev actually named that feature. (Laughter.)


But you can see here you can go ahead and point at a machine, and in this case here I’m pointing at my Mac. We’ll show you all the processes that are running on the Mac. Let’s go ahead and attach to that Safari process, set a break point. Now let’s go back to my Mac and push this again. So, you can see the debugger just broke. (Cheers, applause.) In case this wasn’t obvious, this was really hard to do. (Laughter.)”

There are still plenty of skeptics out there regarding Microsoft’s commitment to build world changing solutions for the web that run outside of Windows and Internet Explorer and time will tell now well we deliver. The teams inside of Microsoft (Silverlight, Dynamic Languages, Tablet PC) that have been working on these platforms have been absolutely buzzing over the last few days. I have spent valuable time with these individuals up in Vegas and earlier this year in Seattle… they are technologists… they love the global potential of their work and MIX for them (and for so many others) is their coming out party!


Ryan Stewart, Scott Guthrie and then Scott Barnes did a great job summing up Silverlight so I’m not going to cover that off here but there is one point I do want to quickly address. There is a bit of FUD online about Silverlight being a “Flash Killer”. Silverlight is not a rip and replace technology and can happily co-exist on the same page as Flash, AJAX and HTML leveraging the best features of each platform (as I showed in my session at Connect back in March). That said there are some very cool things that people have been building using full blown WPF and more recently the Silverlight 1.1 alpha… take a look at this 1 minute mashup video I built from my favourite demos from these downloaded sessions.

Back in December last year we did our first UX tour where we presented on some of these technologies to New Zealand Web/ UX Designers. Although the event was generally very well received one comment stuck with me from that tour. The comment was as follows… “A pretty lame pitch that your finally doing what Flash has done for 10 years (except 3D).”


There is a lot of “opinions” out there and it often hard to find “independent” reviews of the technologies in this space. All I will say on this topic is that if you are a flash designer/ developer take a look at what Silverlight can offer you. One of the most compelling demo’s for me is the Chess Game where you can play Silverlight JScript (view source enabled 😉 vs compiled .NET Silverlight and also the Dynamic Language Runtime Console written in Silverlight 1.1 check out John and Jim’s Just Glue it Video to learn more about this one.


If you are a developer I recommend taking a look at the Silverlight 1.1 Developer Reference poster. When I first saw this a couple of days before MIX there were a couple of  things that lept out at me…



1. The poster announces Silverlight 1.1 support for Windows 2000 and Opera as coming soon… very cool!


What about Linux desktop? Well this is from the Silverlight FAQ’s


“Microsoft is gathering feedback from customers like you on Silverlight and to help determine which platforms should be supported in the future.”


Miguel thinks it will happen!


A while ago I got very excited about inking in WPF. I did not expect this to be ported to Silverlight the way it has been! The text recognition built into Vista is incredible (I used it to handwrite this entire blog post) and I thought there was NO WAY this could be ported into Silverlight since it is so embedded in the platform… but I didn’t think of the alternative. Incorportate XAML inking support into Silverlight then use the ASP.NET Futures AJAX features to pass the XAML of the ink stroke asynchronously to the server for recognition… very cool! If you are interested in this the inking in Silverlight code and demo is available here.


Now the other thing to mention is that MIX was by not just a technology conference there were a number of very inspiring thought invoking speakers involved as well.


Lou Carbone grabbed me and held me for his entire presentation and Kelly Goto was at her quirky trendy best (1,2) stuckunstuck anybody?


Well that is all for me for now… there is plenty of stuff in here to get a hold of and starting playing with in more depth.


Remember that the WPF Family Show project is available with full source (266kb)for you to learn from. As is the Silverlight Airways sample from the keynote.  The amasing Top Banana Silverlight Video Editor shown in the keynote will soon be available with complete source code… all 50k of it!


Also don’t forget Kevin’s Updated WPF Bag-O-Tricks (Very Cool FlipTile3D piece) and IdentityMen comics!


Tags: MIX07

This posting is provided “AS IS” with no warranties, and confers no rights.

Tale of two adapters — BizTalk WCF Adapter and WCF LOB Adapter

The Microsoft BizTalk Server 2006 R2 will ship with a BizTalk WCF Adapter.  The BizTalk WCF Adapter is a bridge between BizTalk and WCF.


It supports features such as:
























Feature


 


Description


Consume metadata exposed by WCF services


 



At design-time, in a BizTalk Project, right-click, select Add > Add Generated Items > Consume WCF Service, click on Add to invoke BizTalk WCF Service Consuming Wizard.  This wizard will import schemas and BizTalk port binding info XML files into the BizTalk projects.  The port binding info XML files can be used to create properly configured send ports for communicating with WCF services. 


Send messages to WCF services


 


 


BizTalk WCF Adapter includes a WCF transmitter for sending messages to the WCF services.  The BizTalk Send Port needs to be configured with WCF client endpoint information (address, binding and contract).   In BizTalk Administration Console, select one of the following available transport adapters to configure access to WCF services.


 


–          WCF-BasicHttp


–          WCF-NetNamedPipe


–          WCF-NetTcp


–          WCF-WSHttp


–          WCF-NetMsmq (one-way only)


–          WCF-Custom


Receive messages from WCF clients


 


 


BizTalk WCF Adapter includes a WCF receiver for receiving messages from WCF clients.  The BizTalk Receive Location needs to be configured with WCF service endpoint information (address, binding and contract).   In BizTalk Administration Console, select one of the following available transport adapters for enabling receiving messages from WCF clients.


 


–          WCF-BasicHttp


–          WCF-NetNamedPipe


–          WCF-NetTcp


–          WCF-WSHttp


–          WCF-NetMsmq (one-way only)


–          WCF-Custom


–          WCF-CustomIsolated


Publish BizTalk orchestrations and schemas as WCF services


 



From Visual Studio, click on Tools from main menu and select BizTalk WCF Service Publishing Wizard.  This wizard is also available along with other tools in Start > All Programs > Microsoft BizTalk Server 2006. 


 


This feature also allows hosting a non-HTTP service within BTSNtSvc.exe by simply configuring a Receive Location and enabling it within the BizTalk Administration Console (no publishing necessary).


 


BizTalk WCF Adapter Architecture and WCF LOB Adapter SDK


BizTalk WCF Adapter provides full support for the WS-* stack including the various security, reliable messaging and transaction specifications.  The following diagram shows the high level architecture of BizTalk WCF Adapter.



Under the covers, the adapter built using the Adapter SDK i.e. the WCF LOB Adapter,  is a transport channel, enriched with the metadata expressed by the adapter.  The WCF LOB Adapter is surfaced as a WCF binding.  In BizTalk, this adapter is consumed via the BizTalk WCF Adapter.


 


Here are some key points –




  • To consume metadata exposed by the WCF LOB Adapter in a BizTalk Project, use the Consume Adapter Service BizTalk Project Add-In. This provides similar functionality to BizTalk Consume WCF Service with an added value of exploring and filtering the adapter metadata.  The end-result is generation of XML Schemas and port binding info XML files.


  • To send messages to the WCF LOB adapter from BizTalk Server, configure Send Port using WCF-Custom Transport Type and select the adapter binding. 


  • To receive inbound messages from the LOB (target system), configure Receive Location using WCF-Custom Transport Type and select the adapter binding

 The following diagram shows where the WCF-based adapter fits with the BizTalk WCF Adapter Architecture.



 

Tale of two adapters — BizTalk WCF Adapter and WCF LOB Adapter

The Microsoft BizTalk Server 2006 R2 will ship with a BizTalk WCF Adapter.  The BizTalk WCF Adapter is a bridge between BizTalk and WCF.


It supports features such as:
























Feature


 


Description


Consume metadata exposed by WCF services


 



At design-time, in a BizTalk Project, right-click, select Add > Add Generated Items > Consume WCF Service, click on Add to invoke BizTalk WCF Service Consuming Wizard.  This wizard will import schemas and BizTalk port binding info XML files into the BizTalk projects.  The port binding info XML files can be used to create properly configured send ports for communicating with WCF services. 


Send messages to WCF services


 


 


BizTalk WCF Adapter includes a WCF transmitter for sending messages to the WCF services.  The BizTalk Send Port needs to be configured with WCF client endpoint information (address, binding and contract).   In BizTalk Administration Console, select one of the following available transport adapters to configure access to WCF services.


 


–          WCF-BasicHttp


–          WCF-NetNamedPipe


–          WCF-NetTcp


–          WCF-WSHttp


–          WCF-NetMsmq (one-way only)


–          WCF-Custom


Receive messages from WCF clients


 


 


BizTalk WCF Adapter includes a WCF receiver for receiving messages from WCF clients.  The BizTalk Receive Location needs to be configured with WCF service endpoint information (address, binding and contract).   In BizTalk Administration Console, select one of the following available transport adapters for enabling receiving messages from WCF clients.


 


–          WCF-BasicHttp


–          WCF-NetNamedPipe


–          WCF-NetTcp


–          WCF-WSHttp


–          WCF-NetMsmq (one-way only)


–          WCF-Custom


–          WCF-CustomIsolated


Publish BizTalk orchestrations and schemas as WCF services


 



From Visual Studio, click on Tools from main menu and select BizTalk WCF Service Publishing Wizard.  This wizard is also available along with other tools in Start > All Programs > Microsoft BizTalk Server 2006. 


 


This feature also allows hosting a non-HTTP service within BTSNtSvc.exe by simply configuring a Receive Location and enabling it within the BizTalk Administration Console (no publishing necessary).


 


BizTalk WCF Adapter Architecture and WCF LOB Adapter SDK


BizTalk WCF Adapter provides full support for the WS-* stack including the various security, reliable messaging and transaction specifications.  The following diagram shows the high level architecture of BizTalk WCF Adapter.



Under the covers, the adapter built using the Adapter SDK i.e. the WCF LOB Adapter,  is a transport channel, enriched with the metadata expressed by the adapter.  The WCF LOB Adapter is surfaced as a WCF binding.  In BizTalk, this adapter is consumed via the BizTalk WCF Adapter.


 


Here are some key points –




  • To consume metadata exposed by the WCF LOB Adapter in a BizTalk Project, use the Consume Adapter Service BizTalk Project Add-In. This provides similar functionality to BizTalk Consume WCF Service with an added value of exploring and filtering the adapter metadata.  The end-result is generation of XML Schemas and port binding info XML files.


  • To send messages to the WCF LOB adapter from BizTalk Server, configure Send Port using WCF-Custom Transport Type and select the adapter binding. 


  • To receive inbound messages from the LOB (target system), configure Receive Location using WCF-Custom Transport Type and select the adapter binding

 The following diagram shows where the WCF-based adapter fits with the BizTalk WCF Adapter Architecture.



 

BizTalk 2004 and .NET 2.0

Under which version of .NET Framework my code is going to run?
I came across this interesting question in BizTalk newsgroup, “I am just wondering though how my local computer knows which CLR to load for the BizTalk Server 2004 Orchestrations when there is no entry in the BTSNTSvc.exe.config file to specifically point to the .NET 1.1 Framework when .NET 1.1 and 2.0 Frameworks are loaded to my computer. “.

Here is my explanation:

Applications that do not carry a configuration file or at least the supportedRuntime element in their configuration files (unconfigured applications) execute with the version of the framework that was used to build the application, provided that version of the Framework is installed on the local system. The version of the Framework with which the application was built is contained in the header (MANIFEST) of the application (assembly). Executing the following line of code against  Microsoft.XLANGs.BizTalk.Engine.dll in a BizTalk 2004 environment will output the result as v1.1.4322. The same piece of code in BizTalk 2006 environment will output v2.0.50727.

Console.WriteLine(System.Reflection.Assembly.LoadFile(@”C:\Program Files\ Microsoft BizTalk Server 2006\ Microsoft.XLANGs.BizTalk.Engine.dll”).ImageRuntimeVersion);

There are two important things which drives what version of framework will be used at runtime :
1. When the expected version of the Framework is not available, the CLR uses a later version of the Framework in its place. In other words, an unconfigured assembly built with Framework 1.1 executes with 1.1 on a system that has both 1.1 and 2.0 installed. That same assembly executes with the 2.0 Framework on a system with only the 2.0 Framework installed.
2. When it comes to interop scenarios the default behavior of CLR is to load the latest framework. This is because unless the managed assemblies, unmanaged assemblies lack the information in their header that describes the version of the framework (as we seen with the code snippet earlier) the code in question was build with; this leaves the CLR with no choice other than to load the latest available version of the framework.

Some of the assemblies used by BizTalk (both 2004 and 2006) runtime components falls under the second category (interop assemblies), which leaves CLR to load the latest available framework.  If you need to override these default behavior, you can set the supportedRuntime/requiredRunTime in the .config file (BtsNtSvc.exe.config for In-Process host and corresponding IIS config file based on version 5.0 or 6.0 either dllhost.exe.config or w3wp.exe.config for isolated host)  for the process as shown below, which forces to use .NET framework 1.1.

<configuration>

<startup>
<supportedRuntime version=”v1.1.4322″ />
</startup>

</configuration>

Ultimately, this means all managed components called by a particular application (BizTalk 2004) runs on the same version of the Framework.

New Assembly, Old .NET

It’s advisable to build your custom assemblies against the same version of .NET that you will be running them against. i.e .NET 1.1 for BizTalk 2004 and .NET 2.0 for BizTalk 2006. That way you’ll have correct references and avoid surprises from behavior difference between builds.

Custom components that are written to use the .NET Framework 2.0 will not work in BizTalk Server 2004. These components include adaptors, pipeline components, functoids, and user code that may be referenced from orchestration or rules policies. This is because new assemblies cannot be opened on older CLR, just because they don’t understand them, and the runtime will throw BadImageFormatException.

References:

http://support.microsoft.com/kb/841405

http://blogs.msdn.com/suzcook/archive/2003/06/20/57191.aspx

http://blogs.msdn.com/suzcook/archive/2005/01/26/new-assembly-old-net-and-vice-versa.aspx

http://msdn2.microsoft.com/en-us/library/ms994410.aspx

Nandri!

Saravana