by Nick Hauenstein | Jul 7, 2015 | BizTalk Community Blogs via Syndication
Earlier this week, I was revisiting a design for a Logic App that interacted with an event about a business entity that was represented as an XML message. It used data from this XML message to invoke actions later in the process, and relied on the XPath Extractor API App to provide access to the data contained within the XML. It looked something like this:
At the time, the choice to use XPath Extractor API Apps was an alright choice, given that there weren’t really any alternative API Apps in the marketplace that allowed one to cross the XML / JSON divide – JSON being the native tongue of Logic Apps. That has since changed, and upon revisiting the design, it became apparent that using the XPath Extractor was a poor choice.
I wasn’t doing anything complex (e.g., selecting the text inside an element only when that element had an attribute with a specific value and appeared nested inside an element beginning with a certain set of characters), I was just trying to retrieve the values stored within scalar elements within the same location in the XML document each time – elements that I would have simply treated as distinguished fields in BizTalk Server and happily dotted into while editing an expression.
Despite not doing something complex, the original design was using 3 separate API App executions just to read 3 separate values. That seems a little bit wasteful for something that the Logic App runtime would give me for free with JSON data.
Using the Right Tool to Bridge the XML / JSON Divide
So what API App was added into the mix since the original plan for this Logic App? The BizTalk JSON Encoder API App – which provides translation from/to XML/JSON.
It accomplishes this in a similar way to BizTalk Server’s own JSON Encoder / JSON Decoder pipeline components, and like those components also requires an XML schema in order to perform the conversion from JSON to XML. The schema can be written by hand, generated from JSON in the Azure Portal, generated from a Flat-file in the Azure Portal, or created using Visual Studio 2012 with the MABS SDK.
Once you have your schema, you can use the Components tile of the JSONEncoder API App within the Azure Portal to access an interface to upload and provide a name for the schema.
In the case of XML to JSON, the conversion can occur with or without a schema (i.e., a schema isn’t going to be used, but it won’t hurt anything if you upload one either).
Doing Simple Things with Simple Data
So how do we do something simple (e.g., access a few fields) with simple data? Thankfully, the answer is quite easily. First off, you will need to create an instance of the BizTalk JSON Encoder API App. This instance can be re-used for any XML to JSON conversions that you will require. Converting back to XML from JSON assumes that you have created the requisite schemas and uploaded them for the instance. One downside here is that you cannot share schemas between instances (as they are stored in local storage for the API App on the Gateway).
Once you have the API App, you can feed it any arbitrary XML payload and it will provide a nice JSON representation that you can dot into for any later actions in a Logic App. Unfortunately, its flexibility comes at the cost of rich metadata describing the shape of the output (i.e., the designer won’t be able to help you know which nodes will actually exist in the output, regardless of potentially having a schema available).
So let’s make it happen. I have an event about a business entity (product) that looks something like this as XML:
Let’s say that I want to retrieve the ProductName out of this message. In that case, the expression within a Logic App to retrieve the value would look something like this:
@body(‘jsonencoder’).OutputJSON.ProductEvent.ProductName
If the Remove Outer Envelope property on the BizTalk JSON Encoder API App was set to true, then it would look like this instead:
@body(‘jsonencoder’).OutputJSON.ProductName
As shown in the screenshot above, neither of these expressions are going to show up within my nice little drop-down list of values to select. Instead, I must dot into it in trust that it will be there. But how can we be a little bit more sure? We could couple it with an XML Validator, or add a condition on the action based on the logical existence of the node.
Does the simple case work though? Well, after updating the expression:
And then submitting the sample message to the source queue, this was the input/output set of the BizTalk JSON Encoder:
And this was the data that showed up in the request bin:
What If I Have More Complex Data?
What if the data that I have isn’t just a bunch of text in elements, but I have a complex structure with repeating nodes and attribute values? To find out, I loaded up the sample message with some sample data to see.
Running that through the JSON Encoder, I saw this output:
Attributes are represented as properties prefixed with @ and the text included in a node is represented as the value of a property named #text. Repeating nodes are collapsed into an array sharing the name of the node name – perfect for repeating an action against.
Then, When Is the XPath Extractor the Right Answer?
Simple data or complex data might not be the determining factor in the choice between using the XPath Extractor or JSON Encoder API Apps to access data locked up in an XML message. Instead, it looks like the determining factor is how hard it is to describe where that data lives (or doesn’t live) within the content. In all the cases we’ve seen thus far, we referenced by name / location in the document. XPath will shine when we don’t have that information, or when we want information about the content in the document, and as such still deserves a place in the toolbox.
However, just because you’re trying to get data out of XML, and all previous knowledge points to XPath as the answer, it might not be – instead, the answer might be to translate that message into the native tongue of the runtime that’s interacting with it.
What’s Next?
I currently owe all of you readers out there a post about push triggers. I have most of it written, but I’m not yet fully pleased with it. I’ll try to get that out as soon as possible. Additionally, there’s another post that I’m even more excited about, one that I’ve been thinking about for the last 3 years. I’m likely going to be posting that one shortly after WPC.
Stay tuned. There’s heaps that I want to share, but, alas, the constraints of the solar day and the capacity of my human flesh prevent it from happening all at once.
by [email protected] Steef-Jan Wiggers | Jul 1, 2015 | BizTalk Community Blogs via Syndication
It’s been awhile since a BizTalk title hit the market. Colin, Mahindra, Mark and Johann updated Richard Seroter’s well received book SOA Patterns with BizTalk Server 2009. I loved Richards’s book and it inspired me to write a book myself. We have met on several occasions. And last year I had the privilege of meeting Mark and Johann in person in Sydney. Both are enthusiastic integration professionals that with Colin and Mahindra’s aid created and updated this book. Excellent work guys, and respect as writing a book is a challenge!
This book covers BizTalk, WCF, JSON and Rest Support in BizTalk, Azure BizTalk Services, Azure Service Bus, SOA, Schema’s and Endpoints, Asynchronous Communication Patterns, Versioning-, Orchestration Patterns, Frameworks and Tools. That is a broad spectrum of today’s integration capabilities on the Microsoft Platform (on premise and cloud).
If you are new to, intermediate- or well versed in the integration, this book is going to give you more insight into Microsoft’s integration world. The thoughts of these experienced authors and Richard original transcript will help you on your journey to build sustainable integration solutions. Especially now landscape around us is changing fast and integration has become key to success for enterprises to survive.
You read this book in your hand, read on your tablet or computer while enjoying a beer. It’s worth the investment and beneficial to your career in integration. Buy the book online at Packt Online Store, Amazon or perhaps your local bookstore.
Thanks Richard, Colin, Johann, Mark and Mahindra.
Cheers,
Steef-Jan
by [email protected] Steef-Jan Wiggers | Jul 1, 2015 | BizTalk Community Blogs via Syndication
Today I have received an e-mail from Microsoft with exciting news that my MVP status has been renewed again!
For me this is the sixth time to receive this award. The fifth year in the program has been again an awesome experience, which gave me the opportunity to do great things and meet inspiring, very skilled people. I have had some interesting speaking engagement, which were fun to do and were very fulfilling. I learned a lot through speaking thanks to the community and fellow MVP’s. I was able to share my experiences through these speaking gigs and other channels like this blog, MSDN Gallery, and above all the TechNet Wiki.
I would like to thank:
- My MVP old lead William Jansen, and new MVP lead Birgit Huebsch.
- The BizTalk Product Team, Mark Mortimore, Guru Venkataraman, Ed Price, Mandi Ohlinger, Allesandro Teglia, Dan Rosanova, Jon Fancey, Paolo Salvatori, and all other Microsoft employees involved.
- People at my former employers: Rene Brauwers, Eldert Grootenboer, fellow MVP Edward Bakker and many others.
- At my current company DutchWorkz : Rutger van Hagen and colleguaes.
- The BizTalk Crew: Saravana Kumar (BizTalk360), Nino Crudele, Sandro Pereira, and Tord G. Nordahl
- Fellow Microsoft Integration MVP’s: Richard Seroter, Kent Weare, Mikael Håkansson, Johan Hedberg, Stephen W. Thomas, Mick Badran (Azure), Micheal Stephenson, Tomasso Groenendijk, Nicholas Hauenstein, Salvatore Pellitteri, Sam VanHoutte, Glenn Colpeart, Bill Chesnut, Leonid Ganeline, and Ashwin Prabhu, who I got learn even better and supported me in this program.
- The BizTalk community: Mikael Sand, Lex Hegt, Colin Meade, Naushad Alam,Howard S. Edidin, Johann Cooper, Mark Brimble, Mitch VanHelden, Sven Van den Brande, Jérémy Ronk, Maxime Labelle, Jean-Paul Smit, Dean Robertson and the collegueaes at Mexia, Martin Abbott, and many others that make the BizTalk community strong!
- Andrew Slivker from Sentinet.
- Finally my wife Lian and children Stan, Ellis and Cato for their support.
I’m looking forward to another great year in the program.
Cheers,
Steef-Jan
by stephen-w-thomas | Jun 30, 2015 | Stephen's BizTalk and Integration Blog
I was working with Windows Azure Automation using a MSDN account to create a run book that will run nightly to turn off all my running virtual machines.
This is super easy and you area even provided a sample script that all you need to do is set your Active Directory (AD) User Name and your Subscription Name.
Once I completed this and created an Automation Asset of Type Credential for my newly created AD User I was all set to go. The AD User has been added as a co-administrator on the account to allow them access to the virtual machines.
I set up the account like this:

With this configuration I received the following errors.
6/24/2015 8:27:46 PM, Error: Add-AzureAccount : user_realm_discovery_failed: User realm discovery failed: The remote server returned an error: (500)
Internal Server Error.
At Stop-AllAzureVM:35 char:35
+
+ CategoryInfo : CloseError: (:) [Add-AzureAccount], AadAuthenticationFailedException
+ FullyQualifiedErrorId : Microsoft.WindowsAzure.Commands.Profile.AddAzureAccount
6/24/2015 8:27:47 PM, Error: Select-AzureSubscription : The subscription name Azure Pass doesn’t exist.
Parameter name: name
At Stop-AllAzureVM:39 char:39
+
+ CategoryInfo : CloseError: (:) [Select-AzureSubscription], ArgumentException
+ FullyQualifiedErrorId : Microsoft.WindowsAzure.Commands.Profile.SelectAzureSubscriptionCommand
6/24/2015 8:27:47 PM, Error: Get-AzureVM : No default subscription has been designated. Use Select-AzureSubscription -Default <subscriptionName> to
set the default subscription.
At Stop-AllAzureVM:44 char:44
+
+ CategoryInfo : CloseError: (:) [Get-AzureVM], ApplicationException
+ FullyQualifiedErrorId : Microsoft.WindowsAzure.Commands.ServiceManagement.IaaS.GetAzureVMCommand
Lets loos closer at the User Name value setup in the Credential:

That’s right is has a space at the end of the name from doing a copy and paste of the user name.
If you run into this error you will want to check your user name setup under both the Asset Type of Credential and your user name entered in your script.
Once I removed the space everything worked as expected..
Best of luck!