static void CreateSendPort() { // connect to the local BizTalk configuration database BtsCatalogExplorer catalog = new BtsCatalogExplorer(); catalog.ConnectionString = "Server=.;Initial Catalog=BizTalkMgmtDb;Integrated Security=SSPI;"; try { // create a new static one-way SendPort SendPort myStaticOnewaySendPort = catalog.AddNewSendPort(false, false); myStaticOnewaySendPort.Name = "myStaticOnewaySendPort1"; myStaticOnewaySendPort.PrimaryTransport.TransportType = catalog.ProtocolTypes[0]; myStaticOnewaySendPort.PrimaryTransport.Address = "http://sample1"; myStaticOnewaySendPort.SendPipeline = catalog.Pipelines["Microsoft.BizTalk.DefaultPipelines.XMLTransmit"]; // create a new dynamic two-way sendPort SendPort myDynamicTwowaySendPort = catalog.AddNewSendPort(true, true); myDynamicTwowaySendPort.Name = "myDynamicTwowaySendPort1"; myDynamicTwowaySendPort.SendPipeline = catalog.Pipelines["Microsoft.BizTalk.DefaultPipelines.XMLTransmit"]; myDynamicTwowaySendPort.ReceivePipeline = catalog.Pipelines["Microsoft.BizTalk.DefaultPipelines.XMLReceive"]; // persist changes to BizTalk configuration database catalog.SaveChanges(); } catch (Exception e) { catalog.DiscardChanges(); throw e; } }
/// <summary> /// Creates solicit-response HTTP send port /// </summary> /// <param name="uri">Send port URI</param> /// <param name="portName">Send port name</param> /// <param name="receivePort">Name of the receive port to bind this send port to</param> /// <returns>True if successful, otherwise false</returns> public static bool CreateHttpSolicitResponsePort(string uri, string portName, string receivePort, string affiliateApplication, ref string retMsg) { IBtsCatalogExplorer explorer = null; try { string mgmtDBName = "BizTalkMgmtDb"; string mgmtDBServer = "localhost"; ManagementClass groupSettings = new ManagementClass("root\\MicrosoftBizTalkServer:MSBTS_GroupSetting"); foreach (ManagementObject obj in groupSettings.GetInstances()) { mgmtDBName = (string)obj.Properties["MgmtDbName"].Value; mgmtDBServer = (string)obj.Properties["MgmtDbServerName"].Value; } // Get BizTalk Explorer object explorer = new BtsCatalogExplorer(); explorer.ConnectionString = "SERVER=" + mgmtDBServer + ";DATABASE=" + mgmtDBName + ";Integrated Security=SSPI"; // Delete this port if it already exists foreach (ISendPort port in explorer.GetCollection(CollectionType.SendPort)) { if (port.Name.ToLower() == portName.ToLower()) { port.Status = PortStatus.Bound; explorer.RemoveSendPort(port); break; } } explorer.SaveChanges(); // Add send port ISendPort transmitPort = explorer.AddNewSendPort(false, true); transmitPort.Name = portName; ITransportInfo TransInfo = transmitPort.PrimaryTransport; TransInfo.Address = uri; // Set protocol type foreach (IProtocolType protocol in explorer.GetCollection(CollectionType.ProtocolType)) { if (protocol.Name == "HTTP") { TransInfo.TransportType = protocol; } } // Set the transport data string transportTypeData = "<CustomProps>" + "<Address vt=\"8\">" + TransInfo.Address + "</Address>" + "<IsSolicitResponse vt=\"11\">1</IsSolicitResponse>" + "<RequestTimeout vt=\"3\">120</RequestTimeout>" + "<MaxRedirects vt=\"3\">0</MaxRedirects>" + "<ContentType vt=\"8\">text/xml</ContentType>" + "<URI vt=\"8\">" + TransInfo.Address + "</URI>" + "<UseSSO vt=\"11\">1</UseSSO>" + "<AffiliateApplicationName vt=\"8\">" + affiliateApplication + "</AffiliateApplicationName>" + "<AuthenticationScheme vt=\"8\">Basic</AuthenticationScheme>" + "</CustomProps>"; // Set transport config TransInfo.TransportTypeData = transportTypeData; ITransportInfo transInfo = transmitPort.PrimaryTransport; // Set reference to transmit pipeline foreach (IPipeline pipe in explorer.GetCollection(CollectionType.Pipeline)) { if ((pipe.Type == PipelineType.Send) && (pipe.FullName == "Microsoft.BizTalk.DefaultPipelines.PassThruTransmit")) { transmitPort.SendPipeline = pipe; break; } } // For synchronous communications we should set up a receive pipeline foreach (IPipeline pipe in explorer.GetCollection(CollectionType.Pipeline)) { if ((pipe.Type == PipelineType.Receive) && (pipe.FullName == "Microsoft.BizTalk.DefaultPipelines.PassThruReceive")) { transmitPort.ReceivePipeline = pipe; break; } } // Set filter transmitPort.Filter = "<Filter>" + "<Group>" + "<Statement Property=\"BTS.ReceivePortName\" Operator=\"0\" Value=\"" + receivePort + "\" />" + "</Group>" + "</Filter>"; // Enlist and start send port transmitPort.Status = PortStatus.Started; // Remember this created send port explorer.SaveChanges(); } catch (Exception e) { retMsg = e.Message.ToString(); if (explorer != null) { explorer.DiscardChanges(); } return(false); } return(true); }