June 2011 - Posts

Integration @ Sommarkollo 2011
22 June 11 09:43 AM | Johan Hedberg

So, once again it’s that time of the year. Summer. And with it Microsoft Sweden arranges a series of presentations across the country that goes under what word-by-word translates to summer school – Sommarkollo. I’m happy to be presenting about integration in the broad context of the Microsoft Application Infrastructure aka Middleware platform, aka BizTalk Server, Windows Server AppFabric and Windows Azure AppFabric. A lot of the content will be focused around Azure AppFabric, simply because that’s where most things are happening at the moment (1) (2).

image

Find the signup to my afternoon slot in Gothenburg on Tuesday the 28th of June here, and the same content in a morning slot in Stockholm on Thursday the 30th of June here.

Right now I’m at ~60 slides and 12 demos but I’m hoping to get access to the newly released Application Manager and Composition soon so I have time to incorporate some of that as well. We’ll see.

Also take a look at the pdf that nicely summarizes all available sessions.

See you there.

/Johan

BizTalk Mapper - How-to execute xslt statements and use the result as input to other functoids
10 June 11 07:09 AM | Johan Hedberg | 1 comment(s)

This post will present a short demonstration of how to use the result of a Scripting functoid doing XSLT to something else then creating a node in the destination document.

This post relies on the following concept, and your familiarity with them:

The sample is simple, and what it does could be solved in a much simpler way. I am not out to show of some complex application – I want to show a very simple example, and let you apply it to whatever complex scenario where you think it may be a fit.

Here is the map:

image

Given this (extremely simple) input:

<ns0:Root xmlns:ns0="http://SwebugMapping.C">
  <Cars>
    <Car>
      <Registration>Registration_0</Registration>
      <Brand>Brand_0</Brand>
      <Color>Color_0</Color>
    </Car>
  </Cars>
</ns0:Root>

It will create the same output (phew!). Nothing fancy by far.

As you might have seen from the screenshot though, the magic of it all, and what I want to show, is how I use xslt to transfer the data via an (for this small scenario) obscure and unneccesarily complex yet (for more demanding scenarios) extremely powerful and dynamic mix in of xslt in an otherwise “normal” map. There are scenarios where this is very useful.

The first functoid uses the global variable conecept to create an global variable. It also holds a method returning a void that allows it to be connected to the root node of the destination without creating an output. Additionally it uses a trick where a scripting functoid will allow you to specify multiple methods within the functoids script, although only the first will be the one triggered to create the functoids output. This second method will be used to update the value of the global variable.

string MyStringValue;

void initglobals ()
{}

void SetMyStringValue(string s)
{
  MyStringValue = s;
}

The second functoid uses and scripting functoid with the xslt call template to transfer the registration node. But it also, in bold and italic below, calls the user defined csharp method we created in the first functoid that updates the global variable. It can perform virtually any type of xslt logic and that pass that in as a parameter, like the keyed cumulative sum – but in this case simply selects the value of the Color node and sets that value. Like I said – I’m not out to present a complex scenario. I’m out to make it simple to understand. Putting it to good use in a complex scenario is your job!

<xsl:template name="MyXsltCallTemplate">
  <xsl:param name="registration" />
  <xsl:variable name="var:u1" select="userCSharp:SetMyStringValue(string(Color/text()))" />
  <xsl:element name="Registration">
    <xsl:value-of select="$registration" />
  </xsl:element>
</xsl:template>

Lastly the third scripting functoid simply outputs the value of the global variable completing the map that creates the same output as it got input.

public string GetMyStringValue()
{
  return MyStringValue;
}

Cool huh? At least I hope I got you thinking about how to combine the power of xslt and the BizTalk Mapper for those complex scenarios where direct usage of xslt just makes so much more sense then trying to get the same result out of mad series of chaining of “regular” functoids which sometime border on bringing about semi-suicidal thinking.

/Johan

Filed under:
BizTalk Mapper - How-to create global variables
09 June 11 12:20 PM | Johan Hedberg | 4 comment(s)

One of the things that can be fairly useful in BizTalk maps is the ability to create global variables. These can be any .Net class that can be accessed from the map, everything from simple bool or int values to generic classes such as List<string>. You create these from within a c# scripting functoid and can use them from within the same or other scripting functoids.

A good place to create and initialize global variables is in a scripting functoid at the top of the map (or in another standardized location) so you always know where to look for them.

For any functoid to be triggered it needs to be connected to an output node, and it needs to contain (at least) one c# method. Yet the functoid containing your global variable initialization you often do not want creating output. To create a functoid that will initialize your global variables without creating output create a method that return a void. Such a method will not create any output, yet it will – when connected to node in the destination schema - be included in the resulting and called from the xslt. A good practice is to connect this functoid to your Root node, whatever that node might be named.

The following is an example of a map that creates and uses a global variable:

image

The functoids has the following content, from top to bottom:

string myGlobalString = "hello";

void InitGlobals ()
{
// you can do any initialization logic here
}

This code creates a global variable and has an empty method returning void to fulfill requirements yet yield no output. This is really the only snippet needed, the one that shows how to create a global variable, the rest simply show some examples of how to use it.

string GetGlobalString ()
{
  return myGlobalString;
}

This method takes no input, but returns the globally available string that we defined in the first functoid and returns it – just to show that it’s available.

string UpdateAndReturnGlobalString(string s)
{
  myGlobalString = s;
  return myGlobalString;
}

This method takes an input, and then updates the global variable with that input, before returning it. This is just to show that you can do things to your variable – it is not a constant. For example, had this been a collection, you could add items to it.

This post, although something fairly well know within the community of seasoned BizTalk developers, is meant to illustrate how you can think outside the Mapper designer and the xslt box when developing BizTalk maps. I also created it for the purpose of being able to refer to it as I create posts that are more advanced in nature, without having to explain this concept in those posts.

/Johan

Filed under:

This Blog

News

    Messenger

    Twitter Updates

      Follow me on twitter

      Visitors

      Feedburner Subscribers

      Locations of visitors to this page

      Disclaimer

      All material is provided AS IS voiding any thinkable or unthinkable effect it might have for any use whatsoever. There... is that clear enough ;)

      Pages

    Syndication