您的位置:首页 > 其它

BizTalk: 使用 WMI 创建WCF-NetMsmq 接收端口和发送端口

2010-04-08 15:51 357 查看
代码如下:

using System;
using System.Management;
namespace TestWMI
{
class Program
{
static void Main(string[] args)
{
CreateRP("My RP");
CreateRL("My RL", "net.msmq://localhost/test1", "My RP");
CreateSP("My SP", "net.msmq://localhost/test2");
}
// Create Receive Port
static void CreateRP(string receivePortName)
{
try
{
PutOptions options = new PutOptions();
options.Type = PutType.CreateOnly;
ManagementClass objClass = new ManagementClass("root//MicrosoftBizTalkServer", "MSBTS_ReceivePort", null);
ManagementObject objRP = objClass.CreateInstance();
objRP["Name"] = receivePortName;
objRP["IsTwoWay"] = "FALSE";
objRP.Put(options);
}
catch (Exception ex)
{
Console.WriteLine("Exception: " + ex.Message);
}
}
// Create Receive Location
static void CreateRL(string receiveLocationName, string address, string receivePortName)
{
try
{
PutOptions options = new PutOptions();
options.Type = PutType.CreateOnly;
ManagementClass objClass = new ManagementClass("root//MicrosoftBizTalkServer", "MSBTS_ReceiveLocation", null);
ManagementObject objRL = objClass.CreateInstance();
objRL["Name"] = receiveLocationName;
objRL["ReceivePortName"] = receivePortName;
objRL["AdapterName"] = "WCF-NetMsmq";
objRL["HostName"] = "BizTalkServerApplication";
objRL["PipelineName"] = "Microsoft.BizTalk.DefaultPipelines.PassThruReceive, Microsoft.BizTalk.DefaultPipelines, Version=3.0.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35";
objRL["InboundTransportURL"] = address;
objRL.Put(options);
}
catch (Exception ex)
{
Console.WriteLine("Exception: " + ex.Message);
}
}
// Create Send Port
static void CreateSP(string sendPortName, string address)
{
try
{
PutOptions options = new PutOptions();
options.Type = PutType.CreateOnly;
ManagementClass objClass = new ManagementClass("root//MicrosoftBizTalkServer", "MSBTS_SendPort", null);
ManagementObject objSP = objClass.CreateInstance();
objSP["Name"] = sendPortName;
objSP["IsDynamic"] = "FALSE";
objSP["IsTwoWay"] = "FALSE";
objSP["PTTransportType"] = "WCF-NetMsmq";
objSP["SendPipeline"] = "Microsoft.BizTalk.DefaultPipelines.PassThruTransmit, Microsoft.BizTalk.DefaultPipelines, Version=3.0.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35";
objSP["PTAddress"] = address;
objSP.Put(options);
}
catch (Exception ex)
{
Console.WriteLine("Exception: " + ex.Message);
}
}
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: