惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

S
Securelist
C
Cybersecurity and Infrastructure Security Agency CISA
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
S
Security Affairs
Hacker News: Ask HN
Hacker News: Ask HN
L
Lohrmann on Cybersecurity
PCI Perspectives
PCI Perspectives
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
C
Cyber Attacks, Cyber Crime and Cyber Security
Recent Commits to openclaw:main
Recent Commits to openclaw:main
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
MyScale Blog
MyScale Blog
月光博客
月光博客
W
WeLiveSecurity
T
Threat Research - Cisco Blogs
Martin Fowler
Martin Fowler
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
Recorded Future
Recorded Future
The GitHub Blog
The GitHub Blog
Webroot Blog
Webroot Blog
Security Archives - TechRepublic
Security Archives - TechRepublic
TaoSecurity Blog
TaoSecurity Blog
P
Proofpoint News Feed
Google DeepMind News
Google DeepMind News
F
Full Disclosure
U
Unit 42
Jina AI
Jina AI
博客园 - 司徒正美
阮一峰的网络日志
阮一峰的网络日志
L
LINUX DO - 最新话题
宝玉的分享
宝玉的分享
大猫的无限游戏
大猫的无限游戏
The Hacker News
The Hacker News
The Last Watchdog
The Last Watchdog
T
Troy Hunt's Blog
腾讯CDC
T
Threatpost
H
Hacker News: Front Page
P
Palo Alto Networks Blog
博客园 - 聂微东
Last Week in AI
Last Week in AI
有赞技术团队
有赞技术团队
Help Net Security
Help Net Security
L
LINUX DO - 热门话题
N
News and Events Feed by Topic
人人都是产品经理
人人都是产品经理
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
Application and Cybersecurity Blog
Application and Cybersecurity Blog
Spread Privacy
Spread Privacy

博客园 - chnking

Biztalk AS2开发经验总结 BizTalk发布WS-Security的web services BizTalk调用WS-Security的web services BizTalk中利用ESSO保存外部系统用户凭据 biztalk大规模高性能高可用部署方案 Biztalk 2009在Windows 2008 R2环境中的High Availability(Cluster群集)部署(下)--AA模式 Biztalk 2009在Windows 2008 R2环境中的High Availability(Cluster群集)部署(上)--AP模式 biztalk中使用biztalk adapter Pack适配器之一 – WCF-SQL WCF系列_分布式事务(下) WCF系列_分布式事务(上) Biztalk中Host Instance线程控制 使用biztalk API新建Receive Location 主流SOA厂商和相关产品 WCF系列(九) - WCF安全系列(四) - WSHttpBinding绑定之Transport安全模式 WCF系列(八) - WCF安全系列(三) - netTCPBinding绑定之Message安全模式 WCF系列(七) - WCF安全系列(二) - netTCPBinding绑定之Transport安全模式 WCF系列(六) - WCF安全系列(一) - basicHttpBinding 深入biztalk的Sequential Convoys保护 IIS客户端证书访问配置
biztalk在用户代码中构造多部分消息
chnking · 2009-07-20 · via 博客园 - chnking

大家知道,biztalk中可以在orchestration调用外部用户代码进行功能扩展,调用外部方法可以把消息作为参数传给外部方法,当然也可能需要外部方法返回一个消息到orchestration

对于schema类型的消息,在用户代码中直接构造一个XmlDocument的对象返回即可,类似这样:

public static XmlDocument GetXmlDocumentTemplate()

{

    String LOCATION = @"C:\MyTemplateLocation\MyMsgTemplate.xml";

    XmlDocument doc = new XmlDocument();

    doc.Load(LOCATION);

    return doc;

}

但是,如果需要返回的是多部分消息,事情就没这么简单了。

首先,XLANGMessage类没有new构造方法,你不能这样新建一个XLANGMessage消息:

XLANGMessage myXLANGMessage = new XLANGMessage();

Biztalk文档中提供了构造XLANGMessage的方法:

public static XLANGMessage XLANGMessageTest(XLANGMessage inMessage)

{

    XmlDocument XmlVariable = new XmlDocument();

    XmlVariable.LoadXml("<Root>Test</Root>");

    XLANGMessage outMessage = XmlVariable;

    Return outMessage

}

不幸的是,这个方法行不通,在编译的时候就提示:

Cannot implicitly convert type 'System.Xml.XmlDocument' to 'Microsoft.XLANGs.BaseTypes.XLANGMessage'

如果不死心,改成这样:

XLANGMessage outMessage = (XLANGMessage)XmlVariable;

编译后,这样提示:

Cannot convert type 'System.Xml.XmlDocument' to 'Microsoft.XLANGs.BaseTypes.XLANGMessage'

改一下代码,改成这样:

public static XLANGMessage XLANGMessageTest(XLANGMessage inMessage)

{

    XmlDocument XmlVariable = new XmlDocument();

    XmlVariable.LoadXml("<Root>Test</Root>");

    XLANGMessage outMessage = null;

    outMessage[0].LoadFrom(XmlVariable);

    Return outMessage

}

这样,编译时能通过了,但是运行时出错,提示outMessage不是对象的实例。

看来,在用户代码中构造XLANGMessage消息不是一般的困难,怎么都在用户代码中构造不出XLANGMessage

在用户代码中构造XLANGMessage如此难,可是如果在orchestration中使用过XLANGMessage,就会觉得在orchestration里构造一个XLANGMessage好像不是什么难事,那我们变通一下,从orchestraion传一个构造好的XLANGMessage到用户代码,用户代码中修改这个XLANGMessage然后返回就是了。

设计一个简单的例子:

从一个文件夹中读取一个文件,里面有简单的内容:chnking

消息进入orchestration后,orchestration将这个消息传送到外部用户代码,在用户代码中新建一个XLANGMessage,内容为接收进来消息后面加上“Output”字符串,返回orchestration,把这个新建的XLANGMessage消息输出到一个file,这个文件的内容应该为:chnking Output

首先设计一个orchestration

clip_image002

设计两个多部分消息,一个是输入消息MultipartType_In,一个是处理后返回要输出的消息MultipartType_Out,这两个多部分消息都只包含一个part,类型为XmlDocument

构造消息的消息赋值形状中的表达式:

//orchestraion中构造XLANGMessage消息就是这么简单

Msg_Out.MessagePart_Body = new System.Xml.XmlDocument();

Helper.MultiMsg.XLANGMessageTest(Msg_In,Msg_Out);

先在orchestration里用Msg_Out.MessagePart_Body = new System.Xml.XmlDocument(); 构造一个包含XmlDocument类型partXLANGMessage消息,传送到外部Helper.MultiMsg.XLANGMessageTest方法,外部方法修改了这个消息后返回。

外部方法的代码:

/// <summary>

/// 接收一个XLANGMessage,并新建一个XLANGMessage,并返回

/// </summary>

/// <param name="inMessage">接收需要处理的XLANGMessage消息</param>

/// <param name="outMessage">实际返回的XLANGMessage消息</param>

public static void XLANGMessageTest(XLANGMessage inMessage, XLANGMessage outMessage)

{

    //获得输入XLANGMessagepart的数据流

    XLANGPart xlp = inMessage[0];

    Stream sourceStrm = (Stream)xlp.RetrieveAs(typeof(Stream));

    //将数据流转成字符串

    byte[] streamByte = new byte[sourceStrm.Length];

    sourceStrm.Position = 0;

    sourceStrm.Read(streamByte, 0, (int)(sourceStrm.Length));

    string sourceStr = System.Text.Encoding.UTF8.GetString(streamByte);

    //简单处理过程,在输入消息的字符串上加上点内容,然后转成MemoryStream,

    //然后载入到输出消息的part

    sourceStr = sourceStr + " Output";

    byte[] outbyte = System.Text.Encoding.UTF8.GetBytes(sourceStr);

    MemoryStream outputStrm = new MemoryStream(outbyte, 0, outbyte.Length, false, true);

    outputStrm.Position = 0;

    outMessage[0].LoadFrom(outputStrm);

}

测试源代码:MultiPartMsgTest.rar