开发者

Applying two transforms to a message on the send port

I have an urgent need to send a canonical message (M1) out of an orchestration and need to map the canonical message to another message (M2). The resulting message (M2) has to be Wrapped in another request 开发者_运维百科message (M3) before sending it to a web service.

I can't perform the initial transform in the orchestration as I can only deal with the canonical schema internally.

Whats the best way to achieve this 2 stage transform outside of the orchestration?

Thanks in advance!


You could make a pipeline component that applies each map sequentially. Then configure the port to use a pipeline with this component.

private Stream ApplyMap(Stream originalStream, Type mapType)
{   
   var transform = TransformMetaData.For(mapType).Transform;
   var argList = TransformMetaData.For(mapType).ArgumentList;

   XmlReader input = XmlReader.Create(originalStream);
   Stream outputStream = new VirtualStream();

   using (var outputWriter = XmlWriter.Create(outputStream))
   {
      transform.Transform(new XPathDocument(input), argList, outputWriter, null);
   }
   outputStream.Flush();
   outputStream.Position = 0;

   XmlReader outputReader = XmlReader.Create(outputStream);
   return outputReader;
}

Then in the pipeline component's Execute method:

Type mapType1 = Type.GetType("YourMapNamespace.Map1, YourAssemblyName,...");
Type mapType2 = Type.GetType("YourMapNamespace.Map2, YourAssemblyName,...");

Stream originalStream = inmsg.BodyPart.GetOriginalDataStream();
Stream mappedStream = 
   ApplyMap(
     ApplyMap(originalStream, mapType1),
     mapType2
   );
inmsg.BodyPart.Data = mappedStream;
context.ResourceTracker.AddResource(mappedStream);

Note that this example does everything in memory so it could be a problem for large messages. I'll try to find a better example that uses streaming (or worse case, you can use VirtualStream to avoid keeping everything in memory)


If you can use the ESB Toolkit, the ideal approach would be to use an itinerary (Richard Seroter has a good article on that approach here). If that's not an option, here's an approach I've used in the past:

http://blogs.msdn.com/b/chrisromp/archive/2008/08/06/stacking-maps-in-biztalk-server.aspx

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜