Error calling a Receive Pipeline in an Orchestration.

Hi,

I have a custom pipeline component in a Receive Pipeline in which I apply an xsl transformation to the original xml. If I call this pipeline from within an orchestration I get an error in my costruct message shape about an Object not set to an instance of an object. However if the component is in a Send Pipeline and set on a Send Port its OK. I suspect it is the way I construct and return the message somehow.

This is how I call the Pipeline in the orchestration (from within a Message Construction Shape):

outMsgCopy = null;

objPipelinexslt = Microsoft.XLANGs.Pipeline.XLANGPipelineManager.ExecuteReceivePipeline(typeof( Pipelines.Woolworths.xsltTransform), outMsg );

objPipelinexslt.MoveNext();

objPipelinexslt.GetCurrent(outMsgCopy);

outMsgCopy(*) = inMsg(*);

IBaseMessage Microsoft.BizTalk.Component.Interop.IComponent.Execute(IPipelineContext pContext,IBaseMessage pInMsg)

{

//return pInMsg;

IBaseMessagePart bodyPart = pInMsg.BodyPart;

Stream xmlData = bodyPart.Data;

Stream transformedMsg = TransformMessage(xmlData);

// Create a new message

IBaseMessage outputMessage = pContext.GetMessageFactory().CreateMessage();

// Copy message context

outputMessage.Context = pInMsg.Context;

// Create a new body part

IBaseMessagePart newBodyPart = pContext.GetMessageFactory().CreateMessagePart();

// Seek to the start of the stream

if (transformedMsg.CanSeek)

transformedMsg.Seek(0,SeekOrigin.Begin);

// Set the new body part's stream

newBodyPart.Data = transformedMsg;

outputMessage.AddPart("body", newBodyPart,true);

pContext.ResourceTracker.AddResource(newBodyPart);

return outputMessage;

}

privateStream TransformMessage(Stream inputMessage)

{

XslCompiledTransform transformer =newXslCompiledTransform();

byte[] outBytes = System.Text.Encoding.ASCII.GetBytes

(CustomXSLT);

MemoryStream memStream =newMemoryStream();

memStream.Write(outBytes, 0, outBytes.Length);

memStream.Position = 0;

XPathDocument xsltDoc =newXPathDocument((Stream)memStream);

MemoryStream destnStream =newMemoryStream();

transformer.Load(xsltDoc);

XPathDocument doc =newXPathDocument(inputMessage);

transformer.Transform(doc,null, destnStream);

return (Stream)destnStream;

}

[4113 byte] By [JodyPetroni] at [2008-1-7]
# 1

First I don't really understand why you'd call a pipeline component inside a orchestration for xsl transformation. Why not use a map for that? I guess you have good reasons for this but I'd be great if you'd let us know.

However I belive you have to initialize the outMsgCopy to something other than null. What type of message is it?

Even if this example is a bit different it should still give you a few ideas on how to change your code.

Richard Hallgren

http://www.richardhallgren.com/blog

RichardHallgren at 2007-10-2 > top of Msdn Tech,BizTalk Server,BizTalk R2 General...
# 2

Believe me Richard I tried a map but all I get is an error saying "XML document must have a top level element" when I test the map.

I have the source schema, destination schema a script functiod with inline xslt with no links to or from the script functiod.

Jody

JodyPetroni at 2007-10-2 > top of Msdn Tech,BizTalk Server,BizTalk R2 General...
# 3

I have just tried setting the xsl via a file reference on the grid properties and it works so I am doing something in my scripting functiod somewhere!!!

Jody

JodyPetroni at 2007-10-2 > top of Msdn Tech,BizTalk Server,BizTalk R2 General...
# 4

Hi again Jody,

You're quick! Setting the xslt document in the grid properties was supposed to be my next suggestion Wink. But that isn't a final solution for you? Do you do something else in the map that requires you to use the the map in a "ordinary" way? Basically I don't understand why you have to use the map and can't just use the xslt as you have it working now? Please explain. However if you have to use it the "functioid way", have you tested the map using a sample message? What's the output?

If it still isn't working for you post the script you use in the function along with a sample message so we can help you further.

Richard Hallgren

http://www.richardhallgren.com/blog

RichardHallgren at 2007-10-2 > top of Msdn Tech,BizTalk Server,BizTalk R2 General...
# 5

Richard,

My understanding from what I have read is that I can use a script functiod with inline xslt. I didnt want to have a xsl file on disk (ie grid properties). Your right I have it working now through a pipeline component (I could of just used a .net component or an expression shape to convert the document) however I would ideally like to use the map and scripting functiod.

As I mentioned previously the map test is OK and I get the desired output only if I set the xslt via the grid property. If I use a scripting functoid I get the "root element is missing" error.

I dont like it when I cant get something to work that should!! Smile

Jody

JodyPetroni at 2007-10-2 > top of Msdn Tech,BizTalk Server,BizTalk R2 General...
# 6

Jody,

You've got an idea how the Xslt inline script is working (and debugging it), if you look at the generated Xslt text. You've got it by Validate Map command.

Regards,
Leonid Ganeline
http://geekswithblogs.net/leonidganeline/
LeonidGaneline-MVP at 2007-10-2 > top of Msdn Tech,BizTalk Server,BizTalk R2 General...
# 7

Good idea Leonid!

And Jody, if you still don't get it to work I think we need to see the xslt and a test message to be able to help you further. I believe you get the "Root element is missing" message as your map generates a blank output document. Have you read this and tested the map. If so what was the output?

Richard Hallgren

http://www.richardhallgren.com/blog

RichardHallgren at 2007-10-2 > top of Msdn Tech,BizTalk Server,BizTalk R2 General...
# 8

Guys,

Refering to a previous post in this message....The map validates ok (ie input message > xslt > output message is OK) but only if the xslt is defined in the grid property not as inline xslt is a script functiod....

I cant seem to copy screen shots into a post, is this possible, that way I can send a screen shot of my map.

regards

Jody.

JodyPetroni at 2007-10-2 > top of Msdn Tech,BizTalk Server,BizTalk R2 General...