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

推荐订阅源

酷 壳 – 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在用户代码中构造多部分消息 主流SOA厂商和相关产品 WCF系列(九) - WCF安全系列(四) - WSHttpBinding绑定之Transport安全模式 WCF系列(八) - WCF安全系列(三) - netTCPBinding绑定之Message安全模式 WCF系列(七) - WCF安全系列(二) - netTCPBinding绑定之Transport安全模式 - chnking WCF系列(六) - WCF安全系列(一) - basicHttpBinding 深入biztalk的Sequential Convoys保护 IIS客户端证书访问配置
使用biztalk API新建Receive Location
chnking · 2009-07-05 · via 博客园 - chnking

可以使用biztalk提供的ExplorerOM名称空间下的APIbiztalk的各个组件进行管理,做Biztalk Administration Console做的那些管理任务,比如查看biztalk服务器上有多少个application,某个Application中有多少接收端口,有多少发送端口,增加删除Receive Location,增加删除发送端口等等。

BtsCatalogExplorerExplorerOM中的核心类,biztalk中的所有组件都通过BtsCatalogExplorer类对外暴露。

BtsCatalogExplorer的各种操作实际上是对biztalkBizTalkMgmtDb数据库的操作,因为biztalk的静态信息,包括这个biztalk服务上有什么Application,接收端口,发送端口,有什么适配器,handler等等都保存在BizTalkMgmtDb数据库。

如果要对biztalk中的某个组件进行操作,必须先初始化一个BtsCatalogExplorer对象,并将需要操作的那个biztalk服务器相应的BizTalkMgmtDb数据库的连接字符串赋给BtsCatalogExplorerConnectionString属性。

BtsCatalogExplorerbiztalk组件的修改都是在内存中进行,只有当执行到SaveChanges方法时,才会把所有的修改一次性提交到BizTalkMgmtDb数据库做实际的修改。

这里以实例说明使用ExplorerOM对象模型新建receive location过程。

代码下载:CreateReceiveLocation.rar

一、  新建File adapterReceive Location

用下面代码在“My Receive Port”接收端口下新建一个name为“Receive Location6 - Code Created user”的File类型的Receive Location

BtsCatalogExplorer root = new BtsCatalogExplorer();

try

{

    root.ConnectionString = "Data Source=.;Initial Catalog=BizTalkMgmtDb;Integrated Security=SSPI;";

    ReceivePort rp = root.ReceivePorts["My Receive Port"];

    ReceiveLocation rl = rp.AddNewReceiveLocation();

rl.Name = "Receive Location6 - Code Created user";

rl.Address = "c:\\temp\\te*.xml";

    foreach (ReceiveHandler handler in root.ReceiveHandlers)

    {

        if (handler.TransportType.Name == "FILE" && handler.Name == "BizTalkServerApplication")

        {

            rl.ReceiveHandler = handler;

            break;

        }

    }

    Microsoft.BizTalk.ExplorerOM.ProtocolType protocol = root.ProtocolTypes["FILE"];

    rl.TransportType = protocol;

rl.ReceivePipeline = root.Pipelines[typeof(PassThruReceive).FullName, typeof(PassThruReceive).Assembly.FullName];

string proStr = "<CustomProps><RemoveReceivedFileRetryCount vt=\"19\">51</RemoveReceivedFileRetryCount><RemoveReceivedFileMaxInterval vt=\"19\">300001</RemoveReceivedFileMaxInterval><FilePath vt=\"8\">F:\\temp</FilePath><FileMask vt=\"8\">pe*.xml</FileMask><Username vt=\"8\">a</Username><BatchSizeInBytes vt=\"19\">102401</BatchSizeInBytes><PollingInterval vt=\"19\">60001</PollingInterval><BatchSize vt=\"19\">21</BatchSize><Password vt=\"1\">a</Password><FileNetFailRetryInt vt=\"19\">51</FileNetFailRetryInt><RemoveReceivedFileDelay vt=\"19\">11</RemoveReceivedFileDelay><RenameReceivedFiles vt=\"11\">0</RenameReceivedFiles><FileNetFailRetryCount vt=\"19\">51</FileNetFailRetryCount></CustomProps>";

    rl.TransportTypeData = proStr;

    rl.FragmentMessages = Fragmentation.Yes;

    rl.ServiceWindowEnabled = false;

    rl.Enable = true;

    root.SaveChanges();

}

catch (Exception e)

{

    root.DiscardChanges();

    throw e;

}

需要注意的是,ReceiveLocationTransportTypeData属性。不同的适配器有不同的属性集,biztalk通过这个TransportTypeData属性接收这些不同的属性,属性的数据类型是string,实际上是name/value对组成的xml形式的属性集合。类似这样的形式,包括了File adapter所有的定制属性了:

<CustomProps>

  <RemoveReceivedFileRetryCount vt="19">51</RemoveReceivedFileRetryCount>

  <RemoveReceivedFileMaxInterval vt="19">300001</RemoveReceivedFileMaxInterval>

  <FilePath vt="8">F:\temp</FilePath>

  <FileMask vt="8">te*.xml</FileMask>

  <Username vt="8">a</Username>

  <BatchSizeInBytes vt="19">102401</BatchSizeInBytes>

  <PollingInterval vt="19">60001</PollingInterval>

  <BatchSize vt="19">21</BatchSize>

  <Password vt="1" >password</Password>

  <FileNetFailRetryInt vt="19">51</FileNetFailRetryInt>

  <RemoveReceivedFileDelay vt="19">11</RemoveReceivedFileDelay>

  <RenameReceivedFiles vt="11">0</RenameReceivedFiles>

  <FileNetFailRetryCount vt="19">51</FileNetFailRetryCount>

</CustomProps>

ReceiveLocation.Address属性很重要,这个属性就是biztalk Administration ConsoleReceive Location列表中,Receive LocationURI属性,指示这个Location接收消息的位置,这个URI在一个biztalk server上所有Receive Location中必须唯一。

对于File适配器,ReceiveLocation.Address属性由File adaterFilePathFilemask属性组合而成。在新建FileReceive Location时,必须设置ReceiveLocation.Address,如果同时在TransportTypeData设置了FilePathFilemask属性,ReceiveLocation.Address会覆盖FilePathFilemask属性的设置,所以,没必要在TransportTypeData中设置FilePathFilemask属性。

一、  新建FTP adapterReceive Location

同样可以在代码中使用ExplorerOM新建一个使用FTP适配器的Receive Location,下面是代码,跟建立FileLocation稍有不同:

BtsCatalogExplorer root = new BtsCatalogExplorer();

try

{

    root.ConnectionString = "Data Source=.;Initial Catalog=BizTalkMgmtDb;Integrated Security=SSPI;";

    string proStr = "<Config xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\"><serverAddress>chnking1.com</serverAddress><serverPort>21</serverPort><userName>kent</userName><password /><fileMask>1*.xml</fileMask><targetFolder>testFolder1</targetFolder><representationType>binary</representationType><maximumBatchSize>0</maximumBatchSize><maximumNumberOfFiles>0</maximumNumberOfFiles><passiveMode>False</passiveMode><firewallType>NoFirewall</firewallType><firewallPort>21</firewallPort><pollingUnitOfMeasure>Seconds</pollingUnitOfMeasure><pollingInterval>60</pollingInterval><errorThreshold>10</errorThreshold><maxFileSize>100</maxFileSize><uri>ftp://chnking.com:21/testFolder/*.xml</uri></Config>";

    proStr = CreateLocationTransportData(proStr);

    ReceivePort rp = root.ReceivePorts["My Receive Port"];

    ReceiveLocation rl = rp.AddNewReceiveLocation();

    rl.Name = "Receive Location FTP - Code Created";

    rl.Address = "ftp://chnking.com:21/testFolder/t*.xml";

    foreach (ReceiveHandler handler in root.ReceiveHandlers)

    {

        if (handler.TransportType.Name == "FTP" && handler.Name == "BizTalkServerApplication")

        {

            rl.ReceiveHandler = handler;

            break;

        }

    }

    Microsoft.BizTalk.ExplorerOM.ProtocolType protocol = root.ProtocolTypes["FTP"];

    rl.TransportType = protocol;

    rl.ReceivePipeline = root.Pipelines[typeof(PassThruReceive).FullName, typeof(PassThruReceive).Assembly.FullName];

    rl.TransportTypeData = proStr;

    rl.FragmentMessages = Fragmentation.Yes;

    rl.ServiceWindowEnabled = false;

    rl.Enable = true;

    root.SaveChanges();

}

catch (Exception e)

{

    root.DiscardChanges();

    throw e;

}

FTP适配器具有的定制属性有下面这些:

<Config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">

  <serverAddress>chnking.com</serverAddress>

  <serverPort>21</serverPort>

  <userName>kent</userName>

  <password />

  <fileMask>*.xml</fileMask>

  <targetFolder>testFolder</targetFolder>

  <representationType>binary</representationType>

  <maximumBatchSize>0</maximumBatchSize>

  <maximumNumberOfFiles>0</maximumNumberOfFiles>

  <passiveMode>False</passiveMode>

  <firewallType>NoFirewall</firewallType>

  <firewallPort>21</firewallPort>

  <pollingUnitOfMeasure>Seconds</pollingUnitOfMeasure>

  <pollingInterval>60</pollingInterval>

  <errorThreshold>10</errorThreshold>

  <maxFileSize>100</maxFileSize>

</Config>

但是跟File适配器不同,FTP适配器需要的TransportTypeData比较特别,需要下面的形式:

<CustomProps>

  <AdapterConfig vt="8">

    <!--定制配置属性的xml字符串形式-->

  </AdapterConfig>

</CustomProps>

需要把前面<Config>节部分的内容转成字符串格式,然后嵌入到<CustomProps><AdapterConfig>节点下,代码中proStr = CreateLocationTransportData(proStr);就是用来做这个转换的:

private static string CreateLocationTransportData(string configString)

{

    XmlDocument xd = new XmlDocument();

    XmlElement xeRoot = xd.CreateElement("CustomProps");

    xd.AppendChild(xeRoot);

    XmlElement xeConfig = xd.CreateElement("AdapterConfig");

    xeRoot.AppendChild(xeConfig);

    XmlAttribute xaVT = xd.CreateAttribute("vt");

    xeConfig.Attributes.Append(xaVT);

    xaVT.Value = "8";

    XmlDocument myXmlDocument = new XmlDocument();

    myXmlDocument.LoadXml(configString);

    xeConfig.InnerText = myXmlDocument.DocumentElement.OuterXml;

    return xd.InnerXml;

}

处理过的TransportTypeData数据是这样的:

<CustomProps>

  <AdapterConfig vt="8">&lt;Config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"&gt;&lt;serverAddress&gt;chnking1.com&lt;/serverAddress&gt;&lt;serverPort&gt;21&lt;/serverPort&gt;&lt;userName&gt;kent&lt;/userName&gt;&lt;password /&gt;&lt;fileMask&gt;1*.xml&lt;/fileMask&gt;&lt;targetFolder&gt;testFolder1&lt;/targetFolder&gt;&lt;representationType&gt;binary&lt;/representationType&gt;&lt;maximumBatchSize&gt;0&lt;/maximumBatchSize&gt;&lt;maximumNumberOfFiles&gt;0&lt;/maximumNumberOfFiles&gt;&lt;passiveMode&gt;False&lt;/passiveMode&gt;&lt;firewallType&gt;NoFirewall&lt;/firewallType&gt;&lt;firewallPort&gt;21&lt;/firewallPort&gt;&lt;pollingUnitOfMeasure&gt;Seconds&lt;/pollingUnitOfMeasure&gt;&lt;pollingInterval&gt;60&lt;/pollingInterval&gt;&lt;errorThreshold&gt;10&lt;/errorThreshold&gt;&lt;maxFileSize&gt;100&lt;/maxFileSize&gt;&lt;/Config&gt;

  </AdapterConfig>

</CustomProps>

对于FTP适配器,ReceiveLocation.Address属性由FTP adaterserverAddressserverPorttargetFolderfileMask属性组合而成,但是在新建FTP Receive Location的代码中ReceiveLocation.AddressTransportTypeDataserverAddress等属性也都需要设置,所以请保证两边设置的值是一致的。