Exemplo n.º 1
0
        /// <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);
        }
Exemplo n.º 2
0
        /// <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);
        }