locked
Biztalk receive and send port using c# RRS feed

  • Question

  • HI Experts,

    I need to configure my receive port and send port using c#.

    following properties should be given in receive port using c#

    1.)I am using some receive port  authentication here for that how can i configure in c#

      myreceivePort.Name = "MyPort";
                myreceivePort.Authentication  =  AuthenticationType.RequiredDropMessage;

    I need to set UserName and Password to the port..How can I do so?


    Monday, February 24, 2014 6:28 PM

Answers

  • Here is the complete code I have used for your purpose..Change the config value as per you requirement:

     public 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 == "FILE")
                        {
                            myreceiveLocation.ReceiveHandler = handler;
                            break;
                        }
                    }
    
                    //Associate a transport protocol and URI with the receive location.
                    foreach (ProtocolType protocol in root.ProtocolTypes)
                    {
                        if (protocol.Name == "FILE")
                        {
                            myreceiveLocation.TransportType = protocol;
                            break;
                        }
                    }
    
                    myreceiveLocation.Address = "\\\\MRASHWINPRABHU\\Try1\\TryBizTalk\\TryRoutingFailure\\In\\*.*";
    
    
                string UserName = "newUser";
                string Password = "NewPassword";                
    
                string ReceiveLocationTransportTypeData = "<CustomProps><RemoveReceivedFileDelay vt=\"19\">10</RemoveReceivedFileDelay><RemoveReceivedFileMaxInterval vt=\"19\">300000</RemoveReceivedFileMaxInterval><FileMask vt=\"8\">*.*</FileMask><RemoveReceivedFileRetryCount vt=\"19\">5</RemoveReceivedFileRetryCount><FileNetFailRetryInt vt=\"19\">5</FileNetFailRetryInt><PollingInterval vt=\"19\">60000</PollingInterval><Username vt=\"8\">Tester1</Username><Password vt=\"1\">pASSWORD</Password><BatchSizeInBytes vt=\"19\">102401</BatchSizeInBytes><RenameReceivedFiles vt=\"11\">0</RenameReceivedFiles><FileNetFailRetryCount vt=\"19\">5</FileNetFailRetryCount><BatchSize vt=\"19\">20</BatchSize></CustomProps>";
    
                System.Xml.XmlDocument docTransportTypeData = new System.Xml.XmlDocument();
                docTransportTypeData.LoadXml(System.Web.HttpUtility.HtmlDecode(ReceiveLocationTransportTypeData));
    
                docTransportTypeData.LoadXml(ReceiveLocationTransportTypeData);
    
                docTransportTypeData.SelectSingleNode("//Username").InnerText = UserName;
                docTransportTypeData.SelectSingleNode("//Password").InnerText = Password;
    
                ReceiveLocationTransportTypeData = docTransportTypeData.OuterXml;
    
                myreceiveLocation.TransportTypeData = ReceiveLocationTransportTypeData;
    
                    //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;
                }
            }


    If this answers your question please mark it accordingly. If this post is helpful, please vote as helpful by clicking the upward arrow mark next to my reply.

    • Marked as answer by sandydv85 Tuesday, February 25, 2014 1:00 PM
    Tuesday, February 25, 2014 12:30 PM
  • Hi Venkat,

    here is the code which set the UserName and Password for the ReceiveLocation:

    string UserName = "newUser";
            string Password = "NewPassword";                
    
            string ReceiveLocationTransportTypeData = "<CustomProps><RemoveReceivedFileDelay vt=\"19\">10</RemoveReceivedFileDelay><RemoveReceivedFileMaxInterval vt=\"19\">300000</RemoveReceivedFileMaxInterval><FileMask vt=\"8\">*.*</FileMask><RemoveReceivedFileRetryCount vt=\"19\">5</RemoveReceivedFileRetryCount><FileNetFailRetryInt vt=\"19\">5</FileNetFailRetryInt><PollingInterval vt=\"19\">60000</PollingInterval><Username vt=\"8\">Tester1</Username><Password vt=\"1\">pASSWORD</Password><BatchSizeInBytes vt=\"19\">102401</BatchSizeInBytes><RenameReceivedFiles vt=\"11\">0</RenameReceivedFiles><FileNetFailRetryCount vt=\"19\">5</FileNetFailRetryCount><BatchSize vt=\"19\">20</BatchSize></CustomProps>";
    
            System.Xml.XmlDocument docTransportTypeData = new System.Xml.XmlDocument();
            docTransportTypeData.LoadXml(System.Web.HttpUtility.HtmlDecode(ReceiveLocationTransportTypeData));
    
            docTransportTypeData.LoadXml(ReceiveLocationTransportTypeData);
    
            docTransportTypeData.SelectSingleNode("//Username").InnerText = UserName;
            docTransportTypeData.SelectSingleNode("//Password").InnerText = Password;
    
            ReceiveLocationTransportTypeData = docTransportTypeData.OuterXml;
    
            myreceiveLocation.TransportTypeData = ReceiveLocationTransportTypeData;
    

    use this code in the place of your "myreceiveLocation.CustomData". Ensure the variable have your username and Password.

    One point you have to consider while giving the user name & password if its for a FILE adapter is "credentials to access the file folder cannot be supplied while accessing local drive or a mapped network drive.". i.e. since you're using "myreceiveLocation.Address = "C:\\test\\*.txt";" local C-drive in the address, you can't set credetails for the File adapter. Its has to a shared dirve like \\\\SharedDisk\\test\\*.txt

     

    If this answers your question please mark it accordingly. If this post is helpful, please vote as helpful by clicking the upward arrow mark next to my reply.

    • Marked as answer by sandydv85 Tuesday, February 25, 2014 2:10 PM
    Tuesday, February 25, 2014 12:18 PM

All replies

  • Sorry, but your question doesn't really fit into any BizTalk paradigm.

    Can you explain your business or technical requirements?  Maybe we can suggest an alternative approach.


    Tuesday, February 25, 2014 1:48 AM
    Moderator
  • HI,

    I have a create 100 rcv ports and 100 send ports through the  names defined in .txt file.

    I need to loop the code and create receive and send ports.

    I have configure every thing in receive port except authentication tab(credentials of Username and Password).

    Alrady code is there only thing need to configure is username and password for that..

    Tuesday, February 25, 2014 2:37 AM
  • Ports just doesn't have names alone, you have to set other properties as well.

    Does that txt file has that info also?

    If you got all the port names from some existing server, its better to export the binding file and import into new application

    Tuesday, February 25, 2014 2:48 AM
  • HI, Below is my code.Code is working fine.But i need to add details to authentication tab in  receive location.
     ReceivePort myreceivePort = app.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 = "MyPort";
         
                
                //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 == "FILE")
                   {
                      myreceiveLocation.ReceiveHandler = handler;
                      break;
                   }
                }
    
                //Associate a transport protocol and URI with the receive location.
                foreach (ProtocolType protocol in root.ProtocolTypes)
                {
                   if(protocol.Name == "FILE")
                   {
                      myreceiveLocation.TransportType =  protocol;
                      
                      break;
                   }
                }
                myreceiveLocation.CustomData
                // new BizTalk application
                
                myreceiveLocation.Address = "C:\\test\\*.txt";
                //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 pr

    Tuesday, February 25, 2014 3:01 AM
  • No I don't have them, i need to create receive and send ports automatically using c# code

    Tuesday, February 25, 2014 5:44 AM
  • I think you have to use the ReceiveLocationTransportTypeData property for this.

    The properties are different for every adapter, so the ExplorerOM cannot use intellisense to facilitate this. You can create one port by hand and then export the bindings. Take the transport data section and use that in your C#.


    Jean-Paul Smit | Didago IT Consultancy
    Blog | Twitter | LinkedIn
    MCTS BizTalk 2006/2010 + Certified SOA Architect

    Please indicate "Mark as Answer" if this post has answered the question.

    • Proposed as answer by Jean-Paul Smit Tuesday, February 25, 2014 1:02 PM
    Tuesday, February 25, 2014 9:23 AM
  • Hi Venkat,

    here is the code which set the UserName and Password for the ReceiveLocation:

    string UserName = "newUser";
            string Password = "NewPassword";                
    
            string ReceiveLocationTransportTypeData = "<CustomProps><RemoveReceivedFileDelay vt=\"19\">10</RemoveReceivedFileDelay><RemoveReceivedFileMaxInterval vt=\"19\">300000</RemoveReceivedFileMaxInterval><FileMask vt=\"8\">*.*</FileMask><RemoveReceivedFileRetryCount vt=\"19\">5</RemoveReceivedFileRetryCount><FileNetFailRetryInt vt=\"19\">5</FileNetFailRetryInt><PollingInterval vt=\"19\">60000</PollingInterval><Username vt=\"8\">Tester1</Username><Password vt=\"1\">pASSWORD</Password><BatchSizeInBytes vt=\"19\">102401</BatchSizeInBytes><RenameReceivedFiles vt=\"11\">0</RenameReceivedFiles><FileNetFailRetryCount vt=\"19\">5</FileNetFailRetryCount><BatchSize vt=\"19\">20</BatchSize></CustomProps>";
    
            System.Xml.XmlDocument docTransportTypeData = new System.Xml.XmlDocument();
            docTransportTypeData.LoadXml(System.Web.HttpUtility.HtmlDecode(ReceiveLocationTransportTypeData));
    
            docTransportTypeData.LoadXml(ReceiveLocationTransportTypeData);
    
            docTransportTypeData.SelectSingleNode("//Username").InnerText = UserName;
            docTransportTypeData.SelectSingleNode("//Password").InnerText = Password;
    
            ReceiveLocationTransportTypeData = docTransportTypeData.OuterXml;
    
            myreceiveLocation.TransportTypeData = ReceiveLocationTransportTypeData;
    

    use this code in the place of your "myreceiveLocation.CustomData". Ensure the variable have your username and Password.

    One point you have to consider while giving the user name & password if its for a FILE adapter is "credentials to access the file folder cannot be supplied while accessing local drive or a mapped network drive.". i.e. since you're using "myreceiveLocation.Address = "C:\\test\\*.txt";" local C-drive in the address, you can't set credetails for the File adapter. Its has to a shared dirve like \\\\SharedDisk\\test\\*.txt

     

    If this answers your question please mark it accordingly. If this post is helpful, please vote as helpful by clicking the upward arrow mark next to my reply.

    • Marked as answer by sandydv85 Tuesday, February 25, 2014 2:10 PM
    Tuesday, February 25, 2014 12:18 PM
  • Here is the complete code I have used for your purpose..Change the config value as per you requirement:

     public 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 == "FILE")
                        {
                            myreceiveLocation.ReceiveHandler = handler;
                            break;
                        }
                    }
    
                    //Associate a transport protocol and URI with the receive location.
                    foreach (ProtocolType protocol in root.ProtocolTypes)
                    {
                        if (protocol.Name == "FILE")
                        {
                            myreceiveLocation.TransportType = protocol;
                            break;
                        }
                    }
    
                    myreceiveLocation.Address = "\\\\MRASHWINPRABHU\\Try1\\TryBizTalk\\TryRoutingFailure\\In\\*.*";
    
    
                string UserName = "newUser";
                string Password = "NewPassword";                
    
                string ReceiveLocationTransportTypeData = "<CustomProps><RemoveReceivedFileDelay vt=\"19\">10</RemoveReceivedFileDelay><RemoveReceivedFileMaxInterval vt=\"19\">300000</RemoveReceivedFileMaxInterval><FileMask vt=\"8\">*.*</FileMask><RemoveReceivedFileRetryCount vt=\"19\">5</RemoveReceivedFileRetryCount><FileNetFailRetryInt vt=\"19\">5</FileNetFailRetryInt><PollingInterval vt=\"19\">60000</PollingInterval><Username vt=\"8\">Tester1</Username><Password vt=\"1\">pASSWORD</Password><BatchSizeInBytes vt=\"19\">102401</BatchSizeInBytes><RenameReceivedFiles vt=\"11\">0</RenameReceivedFiles><FileNetFailRetryCount vt=\"19\">5</FileNetFailRetryCount><BatchSize vt=\"19\">20</BatchSize></CustomProps>";
    
                System.Xml.XmlDocument docTransportTypeData = new System.Xml.XmlDocument();
                docTransportTypeData.LoadXml(System.Web.HttpUtility.HtmlDecode(ReceiveLocationTransportTypeData));
    
                docTransportTypeData.LoadXml(ReceiveLocationTransportTypeData);
    
                docTransportTypeData.SelectSingleNode("//Username").InnerText = UserName;
                docTransportTypeData.SelectSingleNode("//Password").InnerText = Password;
    
                ReceiveLocationTransportTypeData = docTransportTypeData.OuterXml;
    
                myreceiveLocation.TransportTypeData = ReceiveLocationTransportTypeData;
    
                    //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;
                }
            }


    If this answers your question please mark it accordingly. If this post is helpful, please vote as helpful by clicking the upward arrow mark next to my reply.

    • Marked as answer by sandydv85 Tuesday, February 25, 2014 1:00 PM
    Tuesday, February 25, 2014 12:30 PM
  • Excellent answer Prabhu..Thanks a lot.....great work..thanks...
    Tuesday, February 25, 2014 1:01 PM