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

推荐订阅源

酷 壳 – CoolShell
酷 壳 – CoolShell
H
Hacker News: Front Page
P
Palo Alto Networks Blog
T
ThreatConnect
Apple Machine Learning Research
Apple Machine Learning Research
博客园_首页
T
True Tiger Recordings
P
Privacy & Cybersecurity Law Blog
B
Blog
IT之家
IT之家
Last Week in AI
Last Week in AI
F
Full Disclosure
Hacker News: Ask HN
Hacker News: Ask HN
C
Comments on: Blog
Microsoft Azure Blog
Microsoft Azure Blog
C
Cybersecurity and Infrastructure Security Agency CISA
Microsoft Security Blog
Microsoft Security Blog
博客园 - 【当耐特】
N
News and Events Feed by Topic
NISL@THU
NISL@THU
腾讯CDC
雷峰网
雷峰网
Security Latest
Security Latest
李成银的技术随笔
M
Microsoft Research Blog - Microsoft Research
L
LangChain Blog
L
Lohrmann on Cybersecurity
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
C
Check Point Blog
Y
Y Combinator Blog
Recent Announcements
Recent Announcements
博客园 - Franky
N
News | PayPal Newsroom
V
V2EX
A
About on SuperTechFans
The Register - Security
The Register - Security
月光博客
月光博客
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
Google Online Security Blog
Google Online Security Blog
MyScale Blog
MyScale Blog
Cisco Talos Blog
Cisco Talos Blog
Vercel News
Vercel News
WordPress大学
WordPress大学
C
Cyber Attacks, Cyber Crime and Cyber Security
The Hacker News
The Hacker News
IntelliJ IDEA : IntelliJ IDEA – the Leading IDE for Professional Development in Java and Kotlin | The JetBrains Blog
IntelliJ IDEA : IntelliJ IDEA – the Leading IDE for Professional Development in Java and Kotlin | The JetBrains Blog
爱范儿
爱范儿
A
Arctic Wolf
L
LINUX DO - 最新话题
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More

博客园 - 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安全模式 - chnking 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