The composed message processing integration pattern implies that a composed message individual records are split up and then routed and processed then aggregate the response into a single message again.
In our example we process Orders from a company just apply a simple transformation that just counts the number of items and then summarize them into a single message again. We will use Flat files as input and output messages. Moreover we will call the receive and send pipelines at runtime in the orchestration and process individual records from the composed message.
First we will create flat file schemas for request and response messages from the flat file schema wizard. We have to create send and receive pipelines in which we will use Flat file assemble and Flat file disassembler components respectively. We have a header in our input flat file so we will create header schema and use it in the receive Pipeline.
Configure the header schema and document schema property of the disassembler component in the receive pipeline. Also configure the document schema property of the of the assembler component in the send pipeline. Keep the schemas and the pipelines project separate from the orchestrations project.
Build the Schemas and Pipelines project and then create another project containing the orchestration. In the first stage of the orchestration call the receive pipeline to disassemble the flat file message. The input and output messages will be flat files so we have to keep the output and input messages of type System.XML.XMLDocument.
To execute the receive pipeline we have to keep the scope of the expression shape as atomic because the pipeline can be executed in the atomic shape. Also when executing the pipeline any failure can occur so we can keep an exception handling block which in our example dumps the message in an error folder.
The Orchestration has three steps execute the receive pipeline, loop through each individual message and make an aggregate message response message by executing the send pipeline that assembles the individual messages.
First Step:

To execute the pipeline add a reference to the Microsoft.XLANGs.Pipeline.dll and Microsoft.BizTalk.Pipeline.dll assemblies. The pipeline is executed by the following static method.
ReceivePipelineOutput = Microsoft.XLANGs.Pipeline.XLANGPipelineManager.ExecuteReceivePipeline(typeof(ShemasAndPipelines.ReceiveCustOrdres), OrdersInputInterchange);
The method takes the type of pipeline and the input message as input parameters and returns an enumerator of type Microsoft.XLANGs.Pipeline.ReceivePipelineOutputMessages. A variable (ReceivePipelineOutput) of this type is created in the atomic scope variables. When we execute the pipeline we can iterate through all the messages with this enumerator. Below is the code written in the execute pipeline expression shape.
Second Step:
Now in the second step iterate all the messages and save it in the input message of type flat file schema which you created from the flat file wizard (OrdersInputMsg).
ReceivePipelineOutput.GetCurrent(OrdersInputMsg);

You can perform any processing during the loop in your orchestration. For e.g. you can have a correlation for sending the order for approval or route the message or save it into the database. In my scenario I had to create a map that counts the items and map it to the destination message (OrderSummary). The output message can be added to the send pipeline by the variable SendPipelineInput of type Microsoft.XLANGs.Pipeline.SendPipelineInputMessages. And then call its static method add which takes in Microsoft.XLANGs.BaseType.XLANGMessage which is the base class for any message.
SendPipelineInput.Add(OrderSummary);
OrderSummary message is constructed in the transform shape and each message is then added to a message collection of send pipeline.
Step 3:
In the last step we execute the send pipeline to assemble our collection of messages into a single composite message.

The send pipeline is executed from the code given below in which ExecuteSendPipeline method is executed which takes the type of pipeline, SendPipelineInput variable which holds the collection of the output messages and the Output message of type System.XML.XMLDocument.
Microsoft.XLANGs.Pipeline.XLANGPipelineManager.ExecuteSendPipeline(typeof(ShemasAndPipelines.SendCustOrdersPipeline), SendPipelineInput, OrdersOutputInterchange);
Build and deploy the project, also note that keep the pipelines as Passthrough in the receive location as well as the send port.
technorati tags : BizTalk


RSS - Posts
Hi Abdul,
First, thanks for sharing your Biztalk knowledge.
Secondly, I am new to biztalk and went through your article ‘Calling Send and Receive Pipelines from the orchestration expression shapes’
and unfortunately I did not managed to have it working.
Will it be possible if you could send me a working copy of your code to see what I am doing wrong, if it’s not too much asked.?
Cheers,
Walid
Walid,
I will send you the working example of my project. May be I’ll upload it to my blog when I come back after weekend.
Thanks
Abdul
Hi Walid,
Here is the sample you asked. Change the extension to .rar.
http://abdulrafaysbiztalk.wordpress.com/files/2009/06/processingflatfiles.doc
Thanks,
Abdul
I downloaded you sample. When I build the solution befor deplying I got 2 errors:
Error 2 use of unassigned local variable ‘ReceivePipelineOutput’ C:\Users\Administrator\Downloads\ComposedMessageProcessing\ProcessingFlatFiles\FFProcessor.odx 464 51
Error 3 use of unassigned local variable ‘ReceivePipelineOutput’ C:\Users\Administrator\Downloads\ComposedMessageProcessing\ProcessingFlatFiles\FFProcessor.odx 471 52
Actually the variable ‘ReceivePipelineOutput’ was defined in atomic scope. I don’t know why i got the error.
Best Regards, Vinh
Can you assign NULL to the variable ReceivePipelineOutput and see if it works. It compiled at my side.
Hi Abdul,
Thanks for your prompt reply.
I Put the following in Message assignment under loop:
ReceivePipelineOutput = null;
OrderSchema = null;
ReceivePipelineOutput.GetCurrent(OrderSchema);
Then build the solution. One error is gone and stillI got one error left:
Error 2 use of unassigned local variable ‘ReceivePipelineOutput’ C:\Users\Administrator\Downloads\ComposedMessageProcessing\ProcessingFlatFiles\FFProcessor.odx 464 51
It’s in ‘ReceivePipelineOutput.MoveNext()’ under loopthroughbatch.
By the way, I am using VS2008 under Windows 2008 with BizTalk 2009.
Best Regards,
Vinh
Ok I have checked my codes and it gave me an error. Can you add a shape in your orchestration in the beginning and assign null to ReceivePipelineOutput variable. The project will then compile. Remove the null assignments in rest of the orchestration.
Hi Abdul
I put an Expression Shape just in front of LoopThroughBatch and put ReceivePipelineOutput = null; as the expression.
I can build the solution successfully, and will deploy/test the solution.
Thank you so much for the article and your promt response.
Best Regards,
Vinh
Hi Abdul,
Thanks so much for this invaluable information, I am new to Biztalk and I have successfully built and deployed the solution but when I drop orders.txt into the receive folder, I don’t get any output or error and I got on the BT admin, this error in the Application event log “Uncaught exception (see the “inner exception below…) Shape name” LoopThroughBatch” exception thrown from sergment 2, progress 14.
Inner Exception: Object reference not set to an instance of an object.”
Any idea of what is missing here.
Thanks in advance.
Hi Abdul,
I managed to resolve this issue and the solution works.
Thanks.