Calling Pipelines with custom property settings from an orchestration

Calling Pipelines with custom property settings from an orchestration

In my previous blog post I explained how to execute pipelines from an orchestration using the default pipeline property settings.
Now I would like to show you how to call pipelines from an orchestration while configuring the pipeline with custom property settings. To achieve this the standard methods wouldn’t suffice.

First of all you’ll need to add some extra functionalities. Here’s my code to achieve this:


using System;
using System.Collections.Generic;
using System.Text;
using System.Xml;
using System.Data.SqlClient;
using System.Runtime.Serialization;

using Microsoft.XLANGs.Pipeline;
using Microsoft.BizTalk.PipelineOM;
using Microsoft.XLANGs.BaseTypes;
using System.IO;
using System.Reflection;
using System.Collections;
using System.Data;
using System.Text.RegularExpressions;
using Microsoft.XLANGs.RuntimeTypes;
using Microsoft.XLANGs.Core;
using MIME;
using System.Net;

namespace TP.BTS.GlobalFunctions
{

public class PipelineInstance
{
internal Microsoft.BizTalk.PipelineOM.Pipeline pipeline = null;

public static PipelineInstance CreateInstance(Type type)
{
PipelineInstance instance = new PipelineInstance();
instance.pipeline = (Pipeline)Activator.CreateInstance(type);
return instance;
}

public void ApplyInstanceConfig(String config)
{
try
{
using (Stream stream = new MemoryStream(Encoding.Unicode.GetBytes(config)))
LoadPerInstanceConfig(pipeline, stream);
}
catch (Exception e)
{
System.Diagnostics.Debug.WriteLine(String.Format("{0}", e));
throw;
}
}

#region Implementation

private static void LoadPerInstanceConfig(Pipeline pipeline, Stream stream)
{
try
{
MethodInfo method =
typeof(Pipeline).GetMethod(
"LoadPerInstanceConfig"
, BindingFlags.NonPublic | BindingFlags.Instance);
method.Invoke(pipeline, new object[] { stream });
}
catch (System.Exception e)
{
System.Diagnostics.Debug.WriteLine(e);
throw;
}
}

#endregion
}

public static class PipelineManager
{
#region receive pipeline
public static ReceivePipelineOutputMessages ExecuteReceivePipeline(Type type, XLANGMessage message)
{
string EmptyConfig =
@"<Root
xmlns:xsd='http://www.w3.org/2001/XMLSchema'
xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'>
<Stages />
</Root>"
;

return ExecuteReceivePipeline(type, EmptyConfig, message);
}

public static ReceivePipelineOutputMessages ExecuteReceivePipeline(Type type, String config, XLANGMessage message)
{
try
{
PipelineInstance pipeline = PipelineInstance.CreateInstance(type);
pipeline.ApplyInstanceConfig(config);
return ExecuteReceivePipeline(pipeline, message);
}
catch (TargetInvocationException e)
{
System.Diagnostics.Debug.WriteLine(e);
ThrowPipelineException(e);
throw;
}
catch (XLANGPipelineManagerException e)
{
throw;
}
catch (Exception e)
{
System.Diagnostics.Debug.Assert(false, String.Format("Unexpected exception: {0}", e));
System.Diagnostics.Debug.WriteLine(e);
throw;
}
}

public static ReceivePipelineOutputMessages ExecuteReceivePipeline(PipelineInstance pipeline, XLANGMessage message)
{
Microsoft.BizTalk.PipelineOM.Pipeline pipelineOM = pipeline.pipeline;

try
{
MethodInfo method =
typeof(XLANGPipelineManager).GetMethod(
"ExecutePipeline"
, BindingFlags.NonPublic | BindingFlags.Static
, null, new Type[] { typeof(ReceivePipeline), typeof(XLANGMessage) }
, null);
return (ReceivePipelineOutputMessages)method.Invoke(null, new object[] { pipelineOM, message });
}
catch (TargetInvocationException e)
{
System.Diagnostics.Debug.WriteLine(e);
ThrowPipelineException(e);
throw;
}
}
#endregion

#region send pipeline
public static void ExecuteSendPipeline(Type type, SendPipelineInputMessages pipelineinputmsg, XLANGMessage message)
{
string EmptyConfig =
@"<Root
xmlns:xsd='http://www.w3.org/2001/XMLSchema'
xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'>
<Stages />
</Root>"
;

ExecuteSendPipeline(type, EmptyConfig, pipelineinputmsg, message);
}

public static void ExecuteSendPipeline(Type type, String config, SendPipelineInputMessages pipelineinputmsg, XLANGMessage message)
{
try
{
PipelineInstance pipeline = PipelineInstance.CreateInstance(type);
pipeline.ApplyInstanceConfig(config);
ExecuteSendPipeline(pipeline, pipelineinputmsg, message);
}
catch (TargetInvocationException e)
{
System.Diagnostics.Debug.WriteLine(e);
ThrowPipelineException(e);
throw;
}
catch (XLANGPipelineManagerException e)
{
throw;
}
catch (Exception e)
{
System.Diagnostics.Debug.Assert(false, String.Format("Unexpected exception: {0}", e));
System.Diagnostics.Debug.WriteLine(e);
throw;
}
}

public static void ExecuteSendPipeline(PipelineInstance pipeline, SendPipelineInputMessages pipelineinputmsg, XLANGMessage message)
{
Microsoft.BizTalk.PipelineOM.Pipeline pipelineOM = pipeline.pipeline;

try
{
MethodInfo method =
typeof(XLANGPipelineManager).GetMethod(
"ExecutePipeline"
, BindingFlags.NonPublic | BindingFlags.Static
, null, new Type[] { typeof(SendPipeline), typeof(SendPipelineInputMessages), typeof(XLANGMessage) }
, null);
method.Invoke(null, new object[] { pipelineOM, pipelineinputmsg, message });
}
catch (TargetInvocationException e)
{
System.Diagnostics.Debug.WriteLine(e);
ThrowPipelineException(e);
throw;
}
}

#endregion

#region Implementation

private static void ThrowPipelineException(Exception innerException)
{
ConstructorInfo constructor =
typeof(XLANGPipelineManagerException).GetConstructor(
BindingFlags.NonPublic | BindingFlags.Instance
, null
, new Type[] { typeof(String), typeof(Exception) }
, null);
throw (XLANGPipelineManagerException)constructor.Invoke(
new object[] {
innerException != null ?
innerException.InnerException.Message != null?
innerException.InnerException.Message : innerException.Message:
String.Empty, innerException });
}

#endregion
}
}

Now, here’s how to execute a receive pipeline using the custom property settings.
First create a variable of type TP.BTS.GlobalFunctions.PipelineInstance (called ReceivePipeline in my example). Also create a variable PipelineOutputMsg of type Microsoft.XLANGs.Pipeline.ReceivePipelineOutputMessages.
This would be the code to execute the pipeline then:


ReceivePipeline =
TP.BTS.GlobalFunctions.PipelineInstance.CreateInstance(typeof(TC_FFRECEIVE.TC_FFRECEIVE));

ReceivePipeline.ApplyInstanceConfig(
@"<Root xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'>
<Stages>
<Stage CategoryId='9d0e4103-4cce-4536-83fa-4a5040674ad6'>
<Components>
<Component Name='TP.BTS.PIPELINES.CustomXMLRECEIVECOMPONENT'>
<Properties />
</Component>
</Components>
</Stage>
<Stage CategoryId='9d0e4105-4cce-4536-83fa-4a5040674ad6'>
<Components>
<Component Name='Microsoft.BizTalk.Component.FFDasmComp'>
<Properties>
<DocumentSpecName vt='8'>FLATFILE.ORDERS.FF_ORDERS,FLATFILE.ORDERS, Version=1.0.0.0, Culture=neutral, PublicKeyToken=a8e07cee919011d4</DocumentSpecName>
</Properties>
</Component>
</Components>
</Stage>
</Stages>
</Root>"
);



PipelineOutputMsg = TP.BTS.GlobalFunctions.PipelineManager.ExecuteReceivePipeline(ReceivePipeline,MsgICMTxt);

The XML assigned when calling the ApplyInstanceConfig is the same as you can find when exporting the binding file with the Biztalk Admin Console.
It is that simple :).

Calling a send pipeline with custom property settings would be done like this:
Create a variable SendPipelineInput from type Microsoft.XLANGs.Pipeline.SendPipelineInputMessages. I’ve also used a variable PipelineConfig of type System.String.
Here’s the code I’ve used:


SendPipelineInput.Add(MsgINVOIC_EDI);

PipelineConfig = @"<Root xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'>
<Stages>
<Stage CategoryId='9d0e4101-4cce-4536-83fa-4a5040674ad6'>
<Components>
<Component Name='TP.BTS.PIPELINES.CUSTOMSENDEDIPARTYRESOLUTION.CUSTOMSENDEDIPARTYRESOLUTION'>
<Properties>
<OverrideRcvprn vt='8'>"
+ MsgINVOIC_GEN(ORDERS.ORDERSPropertySchema.RCVPRN) + @"</OverrideRcvprn>
<OverrideRecipient vt='11'>-1</OverrideRecipient>
<OverrideSndprn vt='8'>"
+ MsgINVOIC_GEN(ORDERS.ORDERSPropertySchema.SNDPRN) + @"</OverrideSndprn>
</Properties>
</Component>
</Components>
</Stage>
<Stage CategoryId='9d0e4107-4cce-4536-83fa-4a5040674ad6'>
<Components>
<Component Name='Microsoft.BizTalk.Edi.Pipelines.EdiAssembler'>
<Properties />
</Component>
</Components>
</Stage>
<Stage CategoryId='9d0e4108-4cce-4536-83fa-4a5040674ad6'>
<Components>
<Component Name='TP.BTS.PIPELINES.CustomXMLSENDCOMPONENT'>
<Properties />
</Component>
</Components>
</Stage>
</Stages>
</Root>"
;

OrdersOutputInterchange = null;

TP.BTS.GlobalFunctions.PipelineManager.ExecuteSendPipeline(typeof
(CUSTOM_EDI_SEND.CUSTOM_EDI_SEND), PipelineConfig, SendPipelineInput,OrdersOutputInterchange);

And that should do the trick.

Hope you enjoyed this post.

BizTalk Server 2010 Cookbook-a review

BizTalk Server 2010 Cookbook-a review

biztalk-server-2010-cookbook

It is hard to not point out the fact that this is a cookbook, and there already is a book about BizTalk recipes. It is also hard not to point out the fact that I love cooking but hate using cookbooks

This is a cookbook I really, really like though.

I imagine that you, like me, have a collection of really good BizTalk blog post links in you browser of choice. When you use BizTalk, and when you read up on what others have written, then you bookmark certain posts for safe-keeping. You just know that “this is a good thing to remember for another day”.

This book is like the best collection of links you could possibly have! A really good blog in book-form, or a blog-oriented book. First of all: buy this book. It is a given in any BizTalk developer team. The 25 spent on the book will be paid for over and over again as you save time during development and testing.

BizTalk Server 2010 Cookbook uses a very practical approach to problem solving. This is the only downside to the book. Sometimes it it too focused on how to solve something and not enough is spent on understanding it. Then again the author points you to further reading at the end of each recipe. So if you want to know more about something, you can find it easily. Personally I would like it to have been part of the book but I guess that is not up to me to decide.

The practical approach splits each recipe into different parts. First an introduction to present the challenges or the problem. Then follows a “How to” section, a “how it works” and the aforementioned “There is more”.

Do not be fooled by the subtitle of the book “Quick answers to common problems” as the word “problem” might be associated with “bug” or “issue” and this is not the case. It is rather a case of “How to quickly, understand and perform common tasks” but that is a really bad strapline I agree.

The publisher has a complete listing of the books content and I encourage you read it but I would like to point out some of my personal favorites: BizTalk Server Automation: Patterns, Monitoring using Log4Net and Securing Message Exchange. The last one is in my opinion the best text on the subject I have seen. After reading it I feel that the usage of certificates in BizTalk is no longer hard, and I can understand it. Something I must admit to being part of my ignorance up until now.

So once again: Buy this book. It is smart, practical, well written and really useful.


Blog Post by: Mikael Sand

Win a signed copy of BizTalk Server 2010 Cookbook

Thanks to PackT I have one printed and signed copy of Steef-JanWiggers new book BizTalk Server2010 Cookbookand this can be yours! But there’s a cath, in order to receive this book you need to send me a mail tordgladnordahl@gmail.comwith you shipping address and answer thetwo followingquestions. You start out with 100 points, the one with
Blog Post by: Tord Glad Nordahl

Stockholm, Friday 27th April: Hybrid Applications with Clemens Vasters + Win a Hot Air Balloon Ride!

Stockholm, Friday 27th April: Hybrid Applications with Clemens Vasters + Win a Hot Air Balloon Ride!

The Sweden Windows Azure Group (SWAG) will hold a session on “Hybrid Applications – Building Solutions that span On-Premises Assets and the Cloud” with Clemens Vasters, principle technical lead for the Windows Azure Service Bus. It should be a great session with a lot of inside information from the guy behind the technology.

Microsoft Sweden has been kind enough to give us three “Windows Azure Hot Air Balloon” ride tickets, which we were tempted to use ourselves, but will raffle to three lucky attendees at the meeting. A great way to “move to the cloud”.

BaloonSmall

Date: Friday 27th April, 17:30 – 20:30
Location: knowit Stockholm: Klarabergsgatan 60 4tr

Register here: http://swag10.eventbrite.com/

See you there.

Call pipelines from an orchestration

Call pipelines from an orchestration

Calling a pipeline from an orchestration is quite easy.

First of all you need to add a reference to the Microsoft.XLANGs.Pipeline.dll and Microsoft.BizTalk.Pipeline.dll assemblies. When this is done you’ll be able to execute a receive pipeline as follows:


ReceivePipelineOutput = Microsoft.XLANGs.Pipeline.XLANGPipelineManager.ExecuteReceivePipeline
(typeof(ShemasAndPipelines.ReceiveCustOrdres), OrdersInputInterchange);

To get all messages coming out the pipeline, you’ll have to loop over the batch and get all messages like this:


ReceivePipelineOutput.GetCurrent(OrdersInputMsg);

For the execution of a send pipeline you’ll need to create a variable of type Microsoft.XLANGs.Pipeline.SendPipelineInputMessages. then call the method add on this variable which adds message of type Microsoft.XLANGs.BaseType.XLANGMessage.


SendPipelineInputMessages.Add(OrderSummary);

To execute the send pipeline, you’ll have call the ExecuteSendPipeline method with the just created SendPipelineInputMessages and the output message as follows:


Microsoft.XLANGs.Pipeline.XLANGPipelineManager.ExecuteSendPipeline(typeof
(ShemasAndPipelines.SendCustOrdersPipeline), SendPipelineInput, OrdersOutputInterchange);

This way of executing pipelines will execute the pipelines using the default settings for all pipeline properties. How to execute pipelines from an orchestration with custom settings for the pipeline properties will be explained in my next blogs.

a more detailed explanation can be found here

Weekly Cloud Newsround 2012-16

Weekly Cloud Newsround 2012-16

Filtering the informative, insightful and quirky from the fire hose of cloud-based hype.

The announcement of the Windows Azure hosted media platform has been leading the Azure news stories this week with articles my Mary-Jo, streamingmedia.com and V3. I’m keen to get into testing the preview of this, it would be a great technology to use for the webcasts on my CloudCasts site.

Hovhannes Avoyan continues his Windows Azure Overview series with part 4 looking at Security. The links to the four articles are:

Windows Azure Overview

Windows Azure Overview Part 2: Pros and Cons

Windows Azure Overview Part 3: All About Azure Pricing

Windows Azure Overview Part 4: Security

HPC Wire has an interesting article “Cycle Computing Creates 50,000-Core Supercomputer Through Amazon”, the ability to provision massive compute power for short periods of time is a great use of cloud computing.

Cloud Times has an interesting article on “The Rising Value of Cloud Computing”, whilst Greenpeace question the environmental friendliness of the cloud, naming Apple and Amazon as the main offenders. Apple defend their green credentials in the Guardian, with a nice video of a there new data center, hoping to provide 10% of their energy through solar power.

If you are “not ready to move to the cloud”, you could consider moving to the beach to take a look at Crab Computing. Seems interesting, but I have reservations about high availability when there is a spring tide

Artigo “BizTalk Server – Transformar arquivos de texto (Flat Files) em XML” na Revista “Programar”

Artigo “BizTalk Server – Transformar arquivos de texto (Flat Files) em XML” na Revista “Programar”

For the BizTalk Portuguese Community, I publish an article call “BizTalk Server – How to transform flat files into XML” on the Magazine “Programar” and soon I will translate to English. J%u00e1 est%u00e1 dispon%u00edvel a 34%u00aa edi%u00e7%u00e3o da Revista PROGRAMAR, uma publica%u00e7%u00e3o digital gratuita com diversos artigos relacionados com desenvolvimento de software. Esta edi%u00e7%u00e3o cont%u00e9m […]
Blog Post by: Sandro Pereira

Cannot access a disposed object. Object name: ’TransactionScope’.

Cannot access a disposed object. Object name: ’TransactionScope’.

The adapter “WCF-SQL” raised an error message. Details “System.ObjectDisposedException: Cannot access a disposed object. Object name: ‘TransactionScope’. at System.Transactions.TransactionScope.Complete() at System.ServiceModel.Dispatcher.TransactionRpcFacet.ThreadLeave() at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage7(MessageRpc& rpc)”.   When using WCF-SQL adapter you can obtain this error by requesting a SQL server which doesn’t have MSDTC active.   To clear this issue configure MSDTC like your BizTalk server
Blog Post by: Jeremy Ronk