以下程序将创建一个名为MyApp的Biztalk应用程序,并为该程序添加一个MSMQ类型的接收端口和发送端口。接收端口将从"FORMATNAME:DIRECT=TCP:[FE80::F8F9:67DA:BCF7:7F35]/PRIVATE$/MQIn"处接收消息,然后将消息转发给发送端口。发送端口收到消息后,会将消息发送至FORMATNAME:DIRECT=TCP:[FE80::F8F9:67DA:BCF7:7F35]/PRIVATE$/MQOut"。
using System;
using Microsoft.BizTalk.ExplorerOM;
namespace ExplorerOMTest
{
class Program
{
static void Main(string[] args)
{
BtsCatalogExplorer catalog = null;
try
{
// Connect BizTalk
catalog = new BtsCatalogExplorer();
catalog.ConnectionString = "Data Source=.;Initial Catalog=BizTalkMgmtDb;Integrated Security=SSPI;";
// Create Application
IBizTalkApplication application = catalog.AddNewApplication();
application.Name = "MyApp";
catalog.SaveChanges();
// Create ReceivePort
IReceivePort2 rp = application.AddNewReceivePort(false);
rp.Name = "MyRP";
IReceiveLocation2 rl = rp.AddNewReceiveLocation();
rl.Name = "MyRL";
rl.TransportType = catalog.ProtocolTypes["MSMQ"];
rl.ReceivePipeline = catalog.Pipelines["Microsoft.BizTalk.DefaultPipelines.PassThruReceive"];
rl.Address = @"FORMATNAME:DIRECT=TCP:[FE80::F8F9:67DA:BCF7:7F35]/PRIVATE$/MQIn"; // use IPv6
rl.TransportTypeData = "<CustomProps><AdapterConfig vt=/"8/"><Config ><queue>" + rl.Address + "</queue><uri>" + rl.Address + "</uri><batchSize>20</batchSize><transactional>false</transactional><serialProcessing>false</serialProcessing><onFailure>suspendResumable</onFailure></Config></AdapterConfig></CustomProps>";
// Create SendPort
ISendPort2 sp = application.AddNewSendPort(false, false);
sp.Name = "MySP";
sp.PrimaryTransport.TransportType = catalog.ProtocolTypes["MSMQ"];
sp.PrimaryTransport.Address = @"FORMATNAME:DIRECT=TCP:[FE80::F8F9:67DA:BCF7:7F35]/PRIVATE$/MQOut"; // use IPv6
sp.PrimaryTransport.TransportTypeData = "<CustomProps><AdapterConfig vt=/"8/"><Config ><queue>" + sp.PrimaryTransport.Address + "</queue><uri>" + sp.PrimaryTransport.Address + "</uri><maximumMessageSize>1024</maximumMessageSize><acknowledgeType>None</acknowledgeType><timeOut>4</timeOut><priority>Normal</priority><recoverable>false</recoverable><encryptionAlgorithm>None</encryptionAlgorithm><useAuthentication>false</useAuthentication><segmentationSupport>false</segmentationSupport><transactional>false</transactional><useJournalQueue>false</useJournalQueue><useDeadLetterQueue>true</useDeadLetterQueue><ackTypeEnumsValue>0</ackTypeEnumsValue><timeOutUnits>Days</timeOutUnits><bodyType>8209</bodyType></Config></AdapterConfig></CustomProps>";
sp.SendPipeline = catalog.Pipelines["Microsoft.BizTalk.DefaultPipelines.PassThruTransmit"];
sp.Filter = "<Filter><Group><Statement Property=/"BTS.ReceivePortName/" Operator=/"0/" Value=/"" + rp.Name + "/" /></Group></Filter>";
// Start BizTalk Application
application.Start(ApplicationStartOption.StartAll);
// Save changes
catalog.SaveChanges();
}
catch (Exception ex)
{
// Cancel changes
Console.WriteLine("Exception: " + ex.Message);
if (catalog != null)
catalog.DiscardChanges();
}
}
}
}