C# 在 Biztalk Orchestration 中创建新消息的最佳方法是什么?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/313269/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
What is the best way to create a new message within a Biztalk Orchestration?
提问by chinna
I'm looking for your best solutions for creating a new message instance based on a pre-defined XSD schema to be used within a Biztalk orchestration.
我正在寻找您的最佳解决方案,用于基于要在 Biztalk 编排中使用的预定义 XSD 架构创建新消息实例。
Extra votes go to answers with clear & efficient examples or answers with quality referenced links.
额外的投票用于带有清晰有效示例的答案或带有高质量参考链接的答案。
采纳答案by tomasr
What exactly are you looking for? Is it just creating a new message with a fixed content (like a sort of template)? Or based on something else? You really need to clarify the question and be more specific to get a proper answer.
你究竟在寻找什么?是否只是创建具有固定内容的新消息(例如某种模板)?还是基于别的东西?您确实需要澄清问题并更具体地获得正确的答案。
If you're referring to just creating a message from scratch based with sort of hardcoded content (or close to), then I've found that putting them as embedded resources in a helper C# assembly to be a pretty clean way of doing it.
如果您指的是仅基于某种硬编码内容(或接近)从头开始创建消息,那么我发现将它们作为嵌入资源放入辅助 C# 程序集中是一种非常干净的方法。
回答by Greg Beech
To create a new message you can simply create a new System.Xml.XmlDocument
and assign that to a message variable. You can use it's Load
or LoadXml
methods to load the required content that conforms to the schema.
要创建新消息,您可以简单地创建System.Xml.XmlDocument
一个新消息并将其分配给消息变量。您可以使用它的Load
或LoadXml
方法来加载符合架构的所需内容。
回答by David Hall
There are several options when wanting to create a new instance of a message in a BizTalk orchestration.
当想要在 BizTalk 业务流程中创建消息的新实例时,有多种选择。
I've described the three I usually end up using as well as adding some links at the bottom of the answer.
我已经描述了我通常最终使用的三个,并在答案的底部添加了一些链接。
How to define which is the best method really depends - the XMLDocument method is in some regards the tidiest except that if your schema changes this can break without you knowing it. Scott Colestockdescribes some methods of mitigating that risk.
如何定义最好的方法实际上取决于 - XMLDocument 方法在某些方面是最整洁的,除非您的架构发生更改,这可能会在您不知情的情况下中断。Scott Colestock描述了一些减轻这种风险的方法。
The BizTalk Mapping method is probably the simplest to understand and won't break when the schema changes. For small schemas this can be a good choice.
BizTalk Mapping 方法可能是最容易理解的,并且不会在架构更改时中断。对于小型模式,这可能是一个不错的选择。
For all of these methods an important thing to remember is that if you want to use distinguished fields or promoted properties you will want to create empty elements to populate. You will hit runtime XLANG
errors if you try to assign values to elements that are missing (even though those elements may be optional)
对于所有这些方法,需要记住的重要一点是,如果您想使用区分字段或提升的属性,您将需要创建空元素来填充。XLANG
如果您尝试为缺失的元素赋值(即使这些元素可能是可选的),您将遇到运行时错误
BizTalk Map
BizTalk 地图
The simplest option is to just use a BizTalk map - you don't even necessarily need to map anything into the created instance.
最简单的选择是只使用 BizTalk 映射 - 您甚至不需要将任何内容映射到创建的实例中。
To create empty elements you can just map in a string concatenation functoid with an empty string parameter.
要创建空元素,您只需在带有空字符串参数的字符串连接 functoid 中进行映射。
Assign one message to another
将一封邮件分配给另一封邮件
If you want to create a new instance of a message you can simply copy one mesage to another message of the same schema, in a message assignment shape.
如果要创建消息的新实例,只需将一条消息以消息分配形状复制到具有相同架构的另一条消息即可。
Use an XMLDocument variable
使用 XMLDocument 变量
For this you create an orchestration variable of type XMLDocument
and then in a message assignment
use the LoadXML
method to load an XML snippet that matches your schema. You then assign the XMLDocument
to the desired BizTalk message.
为此,您创建一个类型的编排变量,XMLDocument
然后message assignment
使用该LoadXML
方法加载与您的架构匹配的 XML 片段。然后将 分配XMLDocument
给所需的 BizTalk 消息。
varXMLDoc.LoadXml(@"<ns0:SomeXML><AnElementToPopulate></AnElementToPopulate></SomeXML>");
msgYourMessage = varXMLDom;
The inclusion of AnElementToPopulate
allows you to using property promotion to assign to it.
包含AnElementToPopulate
允许您使用属性提升来分配给它。
I seldom remember the syntax to do this off the top of my head, thisis my go to blog entry for reminding myself of the syntax.
我很少记得这样做的语法,这是我的博客条目,用于提醒自己语法。
Another link heredetails some methods.
此处的另一个链接详细介绍了一些方法。
回答by Kelvin Meeks
This tutorial may be of some help:
本教程可能会有所帮助:
BizTalk Server 2006 Tutorial - A Walk Through the Process Creating services with contract-first design using BizTalk Server 2006 R2 and Windows Communication Foundation
BizTalk Server 2006 教程 - 使用 BizTalk Server 2006 R2 和 Windows Communication Foundation 通过契约优先设计创建服务的过程演练
回答by Yossi Dahan
Check out my blog post - Fun with Message Creation in BizTalk- for a basic performance comparison between various options.
查看我的博客文章 -在 BizTalk 中创建消息的乐趣- 以了解各种选项之间的基本性能比较。
回答by Ross Oliver
xsd.exe /classes /namespace:MyNamespace myschemafile.xsd
You can use this to generate c# classes for a given schema file. The result is a .cs file that you can include in one of your solution projects.
您可以使用它为给定的架构文件生成 c# 类。结果是一个 .cs 文件,您可以将其包含在您的解决方案项目之一中。
When using within a "Message Assignment Shape", you can instantiate one of these generated classes, fill out values for all it's properties, then finally assign the Message part to your instance. Biztalk will auto-magically serialize the instance for you. Nice and OO. No need for any fancy xlang stuff.
在“消息分配形状”中使用时,您可以实例化这些生成的类之一,为它的所有属性填写值,然后最后将消息部分分配给您的实例。Biztalk 将自动神奇地为您序列化实例。很好,OO。不需要任何花哨的 xlang 东西。
I didn't really have much luck with some of the other solutions like loading up a temp XmlDocument with hardcoded XML, or going the whole hog and using the documentSpecification.GetDocSchema().CreateXmlInstance() that others have suggested.
对于其他一些解决方案,例如使用硬编码的 XML 加载临时 XmlDocument,或者使用其他人建议的 documentSpecification.GetDocSchema().CreateXmlInstance(),我真的没有太多运气。