对发送端口上的消息应用两个转换

发布于 2024-11-19 03:37:50 字数 179 浏览 3 评论 0 原文

我迫切需要从编排中发送规范消息 (M1),并且需要将规范消息映射到另一条消息 (M2)。生成的消息 (M2) 在发送到 Web 服务之前必须包装在另一个请求消息 (M3) 中。

我无法在编排中执行初始转换,因为我只能在内部处理规范模式。

在编排之外实现这两个阶段转换的最佳方法是什么?

提前致谢!

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!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

荒岛晴空 2024-11-26 03:37:50

您可以创建一个按顺序应用每个映射的管道组件。然后配置端口以使用此组件的管道。

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;
}

然后在管道组件的 Execute 方法中:

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);

请注意,此示例在内存中执行所有操作,因此对于大消息来说可能会出现问题。我将尝试找到一个使用流的更好的示例(或者更糟糕的情况,您可以使用 VirtualStream 来避免将所有内容保留在内存中)

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)

剩余の解释 2024-11-26 03:37:50

如果您可以使用 ESB 工具包,理想的方法是使用行程(Richard Seroter 有一篇关于该方法的好文章 此处)。如果这不是一个选择,这是我过去使用过的方法:

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

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文