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

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);  
            }  
        }  
    }  

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值