static void CreateReceivePort() { BtsCatalogExplorer root = new BtsCatalogExplorer(); try { root.ConnectionString = "Server=.;Initial Catalog=BizTalkMgmtDb;Integrated Security=SSPI;"; //Create a new one way receive port. ReceivePort myreceivePort = root.AddNewReceivePort(false); //Note that if you do not set the name property of the ReceivePort, //it will use the default name generated. myreceivePort.Name = "My Receive Port"; myreceivePort.Tracking = TrackingTypes.AfterReceivePipeline; //Try to commit the changes made so far. If it fails, roll-back //all the changes. root.SaveChanges(); } catch (Exception e) { root.DiscardChanges(); throw e; } }
static void ConfigureReceivePort() { BtsCatalogExplorer root = new BtsCatalogExplorer(); try { root.ConnectionString = "Server=.;Initial Catalog=BizTalkMgmtDb;Integrated Security=SSPI;"; //Create a new two-way receive port. //Passing the false value creates a one-way receive port. ReceivePort myreceivePort = root.AddNewReceivePort(true); myreceivePort.Name = "My Receive Port"; //optional property myreceivePort.Tracking = TrackingTypes.AfterReceivePipeline; //optional //Set the primary receive location. foreach (ReceiveLocation location in myreceivePort.ReceiveLocations) { if (location.Address == "http://abc.com") { myreceivePort.PrimaryReceiveLocation = location; //optional break; } } //Assign the first send pipeline found to process the response message. foreach (Pipeline pipeline in root.Pipelines) { if (pipeline.Type == PipelineType.Send) { myreceivePort.SendPipeline = pipeline; //optional property break; } } myreceivePort.Authentication = AuthenticationType.RequiredDropMessage; //optional //Try to commit the changes made so far. //If the commit fails, roll-back all changes. root.SaveChanges(); } catch (Exception e) { root.DiscardChanges(); throw e; } }
public override void Execute(Context context) { _catalog.Refresh(); // Create port ReceivePort port = _catalog.AddNewReceivePort(false); port.Name = PortName; context.LogInfo(string.Format("Created receive port with name: '{0}'", PortName)); // Create location ReceiveLocation location = port.AddNewReceiveLocation(); location.Name = LocationName; location.Address = Address; location.TransportType = _catalog.ProtocolTypes["FILE"]; location.TransportTypeData = string.Format("<CustomProps><FilePath vt=\"8\">{0}</FilePath><BatchSize vt=\"19\">20</BatchSize><FileMask vt=\"8\">*.*</FileMask><RenameReceivedFiles vt=\"11\">-1</RenameReceivedFiles></CustomProps>", Address); switch (Pipeline) { case ReceiveLocationCreateStep.PipelineType.PassThru: location.ReceivePipeline = _catalog.Pipelines["Microsoft.BizTalk.DefaultPipelines.PassThruReceive"]; break; case ReceiveLocationCreateStep.PipelineType.Xml: location.ReceivePipeline = _catalog.Pipelines["Microsoft.BizTalk.DefaultPipelines.XMLReceive"]; break; } foreach (ReceiveHandler receiveHandler in _catalog.ReceiveHandlers) { if (receiveHandler.TransportType.Name == location.TransportType.Name) { location.ReceiveHandler = receiveHandler; break; } } context.LogInfo(string.Format("Created receive location with name: '{0}', TransportType: '{1}', Address:'{2}', Pipeline:'{3}', Receive handler:'{4}'", LocationName, location.TransportType == null ? string.Empty : location.TransportType.Name, location.Address, location.ReceivePipeline == null ? string.Empty : location.ReceivePipeline.FullName, location.ReceiveHandler == null ? string.Empty : location.ReceiveHandler.Name)); _catalog.SaveChanges(); context.Add(string.Format("ReceiveLocation-{0}", location.Name), location); }
/// <summary> /// Creates receive port with one request-response HTTP receive location /// </summary> /// <param name="virtualDirectory">Virtual directory name</param> /// <param name="portName">Receive port name</param> /// <param name="locationName">Receive location name</param> /// <returns>True if successful, otherwise false</returns> public static bool CreateHttpRequestResponsePort(string virtualDirectory, string portName, string locationName, 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 (IReceivePort port in explorer.GetCollection(CollectionType.ReceivePort)) { if (port.Name.ToLower() == portName.ToLower()) { explorer.RemoveReceivePort(port); break; } } explorer.SaveChanges(); // Add new port IReceivePort receivePort = explorer.AddNewReceivePort(true); receivePort.Name = portName; // Add new location IReceiveLocation rxLocation = receivePort.AddNewReceiveLocation(); rxLocation.Name = locationName; // Set the receive location rxLocation.Address = "/" + virtualDirectory + "/BTSHttpReceive.dll"; // Set the transport type foreach (IProtocolType protocol in explorer.GetCollection(CollectionType.ProtocolType)) { if (protocol.Name == "HTTP") { rxLocation.TransportType = protocol; } } // Set the transport data rxLocation.TransportTypeData = "<CustomProps>" + "<Address vt=\"8\">" + rxLocation.Address + "</Address>" + "<LoopBack vt=\"11\">0</LoopBack>" + "<IsSynchronous vt=\"11\">1</IsSynchronous>" + "<ReturnCorrelationHandle vt=\"11\">0</ReturnCorrelationHandle>" + "<ResponseContentType vt=\"8\">text/html</ResponseContentType>" + "<URI vt=\"8\">" + rxLocation.Address + "</URI>" + "<UseSSO vt=\"11\">1</UseSSO>" + "</CustomProps>"; // Set the receive pipeline foreach (IPipeline pipe in explorer.GetCollection(CollectionType.Pipeline)) { if ((pipe.Type == PipelineType.Receive) && (pipe.FullName == "Microsoft.BizTalk.DefaultPipelines.PassThruReceive")) { rxLocation.ReceivePipeline = pipe; break; } } // Set the receive handler foreach (IReceiveHandler handler in explorer.GetCollection(CollectionType.ReceiveHandler)) { if (handler.TransportType == rxLocation.TransportType) { rxLocation.ReceiveHandler = handler; break; } } foreach (IPipeline pipe in explorer.GetCollection(CollectionType.Pipeline)) { if ((pipe.Type == PipelineType.Send) && (pipe.FullName == "Microsoft.BizTalk.DefaultPipelines.PassThruTransmit")) { receivePort.SendPipeline = pipe; break; } } // Enable this receive location rxLocation.Enable = true; // Save changes explorer.SaveChanges(); } catch (Exception e) { retMsg = e.Message.ToString(); if (explorer != null) { explorer.DiscardChanges(); } return(false); } return(true); }
static void CreateAndConfigureReceiveLocation() { BtsCatalogExplorer root = new BtsCatalogExplorer(); try { root.ConnectionString = "Server=.;Initial Catalog=BizTalkMgmtDb;Integrated Security=SSPI;"; //First, create a new one way receive port. ReceivePort myreceivePort = root.AddNewReceivePort(false); //Note that if you dont set the name property for the receieve port, //it will create a new receive location and add it to the receive //port. myreceivePort.Name = "My Receive Port"; //Create a new receive location and add it to the receive port ReceiveLocation myreceiveLocation = myreceivePort.AddNewReceiveLocation(); foreach (ReceiveHandler handler in root.ReceiveHandlers) { if (handler.TransportType.Name == "HTTP") { myreceiveLocation.ReceiveHandler = handler; break; } } //Associate a transport protocol and URI with the receive location. foreach (ProtocolType protocol in root.ProtocolTypes) { if (protocol.Name == "HTTP") { myreceiveLocation.TransportType = protocol; break; } } myreceiveLocation.Address = "/home"; //Assign the first receive pipeline found to process the message. foreach (Pipeline pipeline in root.Pipelines) { if (pipeline.Type == PipelineType.Receive) { myreceiveLocation.ReceivePipeline = pipeline; break; } } //Enable the receive location. myreceiveLocation.Enable = true; myreceiveLocation.FragmentMessages = Fragmentation.Yes; //optional property myreceiveLocation.ServiceWindowEnabled = false; //optional property //Try to commit the changes made so far. If the commit fails, //roll-back all changes. root.SaveChanges(); } catch (Exception e) { root.DiscardChanges(); throw e; } }