How can I resolve the Party Name

Home Page Forums BizTalk 2004 – BizTalk 2010 How can I resolve the Party Name

Viewing 1 reply thread
  • Author
    Posts
    • #15642

      Hi

       

      I have a case where I receive digitally signed messages. I use a S/MIME component for verifying the signature, I use Party Resolution component to resolve the party. The parties are created and I have the parties’ certificates. I also set the Authentication Required property in the receive port and all messages not sent by one of my registered partners are suspended. So far so good. But I would like to have the party’s name. I have the party’s partyID  (BTS.SourcePartyID) but I need the party name to use in an orchestration. Is it possible to get the name from the ID?

       

      Johan

    • #15643

      How about BTS.SourceParty ? <but notice that the BizTalk official documentation says: This property supports the BizTalk Server 2006 infrastructure and is not intended to be used directly from your code.

       

       

      • #15644

        I have tried that. The BTS.Source does not seem to have a value. I used this code in an expression shape:

        System.Diagnostics.Debug.WriteLine("PID "+Message_1(BTS.SourcePartyID));
        System.Diagnostics.Debug.WriteLine("SourceParty "+Message_1(BTS.SourceParty));

        And the following output:

        And the following output:

        [1444] PID S-1-9-893551331-2747879358-2265075479-3534360612-3810352465-619529870-2917489459-2111898011

        And this XLANG/s error:

        [1444] PID S-1-9-893551331-2747879358-2265075479-3534360612-3810352465-619529870-2917489459-2111898011

        And this XLANG/s error:

        There is no value associated with the property 'BTS.SourceParty' in the message.

        If it is not the right way, what is?

        Johan

         

         

        • #15651

          Does it need to be promoted in order to be accessible at that point in the process?

          • #15654

            I have a small .Net helper class that allows you to cross reference the party properties.

            You can use the static method GetAliasFromSID to retrieve the OrganisationName:

            strPartyName = BTSParty.CrossReference.GetAliasFromSID(Message_1(BTS.SourcePartyID),"OrganisationName");

            Source:

            using System;
            using System.Data;
            using System.Data.SqlClient;
            using System.Management;
            using System.Xml;
            using Microsoft.BizTalk.ExplorerOM;
            using Microsoft.Win32;

            namespace BTSParty
            {
             /// <summary>
             /// Summary description for PartyAliasMapper.
             /// </summary>
             public class CrossReference
             {
              static private object syncRoot = new object();
              static private string MgmtDBConnString = String.Empty;

              public struct PartyDetails
              {
               public string SID;
               public string PartyName;
              }

              public static string GetMgmtDBConnectionString()
              {
               string BTSMgmtDBName = String.Empty, BTSMgmtDBServerName = String.Empty;
               //check to see if the string has already been retrieved.  If not, get it and store it.
               if( MgmtDBConnString.Length == 0 )
               {
                lock( syncRoot )
                {
                 if( MgmtDBConnString.Length == 0)
                 {
                  ManagementObjectSearcher searcher =
                   new ManagementObjectSearcher(@"root\MicrosoftBizTalkServer", "SELECT * FROM MSBTS_GroupSetting");
                  foreach (ManagementObject Group in searcher.Get())
                  {
                   if(Group != null)
                   {
                    Group.Get();
                    BTSMgmtDBName = Group["MgmtDbName"].ToString();
                    BTSMgmtDBServerName = Group["MgmtDbServerName"].ToString();
                   }      
                  }
                  if( BTSMgmtDBName.Length == 0 || BTSMgmtDBServerName.Length == 0 )
                   throw new ApplicationException("Unable to find Management Database Name or Management Database Server Name");

                  // Assuming Integrated Security is being used for database connection.
                  MgmtDBConnString = string.Format("SERVER={0};DATABASE={1};Integrated Security=SSPI", BTSMgmtDBServerName, BTSMgmtDBName);
                 }
                }
               }
               return MgmtDBConnString;
              }

              public static PartyDetails GetPartyFromAlias(string Alias, string Qualifier)
              {
               PartyDetails ThisParty;
               const string GetnvcSIDQueryString = "SELECT bts_party.nvcName, nvcSID " +
                   "FROM bts_party_alias INNER JOIN bts_party " +
                   "     ON bts_party_alias.nPartyID = bts_party.nID " +
                   "   WHERE nvcValue='{0}' AND nvcQualifier='{1}'";

               ThisParty.SID = "s-1-5-7";   // set default SID to "Guest"
               ThisParty.PartyName = "";

               SqlConnection BTSMgmtDBconn = new SqlConnection(GetMgmtDBConnectionString());
               
               //Build the querystring by populating the Alias and Qualifier into the base query
               SqlCommand PartyIdCMD = new SqlCommand(string.Format(GetnvcSIDQueryString, Alias, Qualifier), BTSMgmtDBconn);

               // any exceptions raised here will be reported to the event log by the messaging engine.
               BTSMgmtDBconn.Open();
               SqlDataReader PartyReader = PartyIdCMD.ExecuteReader(CommandBehavior.CloseConnection);
               if(PartyReader.HasRows)
               {
                PartyReader.Read();
                ThisParty.PartyName = PartyReader.GetString(0);
                ThisParty.SID = PartyReader.GetString(1);
               }
               PartyReader.Close();
               BTSMgmtDBconn.Close();

               return ThisParty;
              }
              public static string GetSIDFromAlias(string Alias, string Qualifier)
              {
               string ThisSID = string.Empty;
               const string GetnvcSIDQueryString = "SELECT  nvcSID " +
                   "FROM bts_party_alias INNER JOIN bts_party " +
                   "     ON bts_party_alias.nPartyID = bts_party.nID " +
                   "   WHERE nvcValue='{0}' AND nvcQualifier='{1}'";

               SqlConnection BTSMgmtDBconn = new SqlConnection(GetMgmtDBConnectionString());
               
               //Build the querystring by populating the Alias and Qualifier into the base query
               SqlCommand PartyIdCMD = new SqlCommand(string.Format(GetnvcSIDQueryString, Alias, Qualifier), BTSMgmtDBconn);

               // any exceptions raised here will be reported to the event log by the messaging engine.
               BTSMgmtDBconn.Open();
               SqlDataReader PartyReader = PartyIdCMD.ExecuteReader(CommandBehavior.CloseConnection);
               if(PartyReader.HasRows)
               {
                PartyReader.Read();
                ThisSID = PartyReader.GetString(0);
               }
               PartyReader.Close();
               BTSMgmtDBconn.Close();

               return ThisSID;
              }
              public static string GetAliasFromSID(string SID, string Qualifier)
              {
               string ThisAlias = string.Empty;

               const string GetnvcSIDQueryString = "SELECT bts_party_alias.nvcValue " +
                   "FROM bts_party_alias INNER JOIN bts_party " +
                   "     ON bts_party_alias.nPartyID = bts_party.nID " +
                   "   WHERE bts_party.nvcSID='{0}' AND bts_party_alias.nvcQualifier='{1}'";

               SqlConnection BTSMgmtDBconn = new SqlConnection(GetMgmtDBConnectionString());
               
               //Build the querystring by populating the SID and Qualifier into the base query
               SqlCommand PartyIdCMD = new SqlCommand(string.Format(GetnvcSIDQueryString, SID, Qualifier), BTSMgmtDBconn);

               // any exceptions raised here will be reported to the event log by the messaging engine.
               BTSMgmtDBconn.Open();
               SqlDataReader PartyReader = PartyIdCMD.ExecuteReader(CommandBehavior.CloseConnection);
               if(PartyReader.HasRows)
               {
                PartyReader.Read();
                ThisAlias = PartyReader.GetString(0);
               }
               PartyReader.Close();
               BTSMgmtDBconn.Close();

               return ThisAlias;
              }

              public static string GetCustomPropertyFromSID(string SID, string customPropertyName)
              {
               string ThisProperty = string.Empty;

               const string GetnvcSIDQueryString = "SELECT bts_party.nvcCustomData " +
                   "FROM bts_party" +
                   "   WHERE bts_party.nvcSID='{0}'";

               SqlConnection BTSMgmtDBconn = new SqlConnection(GetMgmtDBConnectionString());
               
               //Build the querystring by populating the SID and Qualifier into the base query
               SqlCommand PartyIdCMD = new SqlCommand(string.Format(GetnvcSIDQueryString, SID), BTSMgmtDBconn);

               // any exceptions raised here will be reported to the event log by the messaging engine.
               BTSMgmtDBconn.Open();
               SqlDataReader PartyReader = PartyIdCMD.ExecuteReader(CommandBehavior.CloseConnection);
               if(PartyReader.HasRows)
               {
                try
                {
                 PartyReader.Read();
                 XmlDocument customData = new XmlDocument();
                 customData.LoadXml( PartyReader.GetString(0));
                 XmlNode propertyNode = customData.SelectSingleNode("/Properties/" + customPropertyName);
                 ThisProperty = propertyNode.InnerText;
                }
                catch(Exception)
                { }
               }
               PartyReader.Close();
               BTSMgmtDBconn.Close();

               return ThisProperty;
              }
             }
            }

            • #15672

              Thanks Greg

              Exactly what i needed. Had some trouble att first but when i found out you spelled OrganizationName wrong in your example and changed it from OrganisationName all worked perfect

               

              Thanks again.

               Johan

               

               

            • #18217

              I tried copying the code for resolving the Party Name, but I get the following exception at runtime: "Inner exception: Syntax error or access violation".

              I've traced it to the line where it fails, but I don't know why it fails.  It fails in GetMgmtDBConnectionString() on the line foreach (ManagementObject Group in searcher.Get())

               

              Does anyone have any ideas as to why I get an access violation iterating through the collection?

              • #18222

                You are getting the access violation on the Searcher.Get(), which is calling the WMI interrface to retrieve the data you need.

                WMI has it own Access Control List, that is managed via Computer Management console

                Open Computer Management
                Open Services and Applications
                Right click WMI Control -> Properties

                Select Security tab
                Expand root and select MicrosoftBiztalkServer
                Click Security button

                Add the user or group that runs the pipeline (??BizTalk Host Users and Biztalk Isolated Host Users) and give full permissions

                 

Viewing 1 reply thread
  • The forum ‘BizTalk 2004 – BizTalk 2010’ is closed to new topics and replies.