Hello Community!
I am trIed to use a Script using C# code, the code take some data from Active Directory, but when I try to run the script I got this error message:
"The TLS/SSL host name does not match the host name in the X.509 certificate", as show the image below:
I don't what kind of certificate I must to install. When I tried to run the all workflow I found this other error message:
"The workflow service is not licensed. [0645-WF1]"
I dont know what is the license or certificate I missing, please any help in this is appreciate!
I left the workflow design and the code I am using:
and the c# code is inside in the script:
namespace WorkflowActivity.Scripting.Script { using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Data.SqlClient; using System.Text; using System.DirectoryServices; using System.DirectoryServices.AccountManagement; using System.DirectoryServices.ActiveDirectory; /// <summary> /// Provides one or more methods that can be run when the workflow scripting activity is performed. /// </summary> public class Script1 : ScriptClass90 { /// <summary> /// This method is run when the activity is performed. /// </summary> protected override void Execute() { string userToFind= GetTokenValue("FindUserToModifyValues_Display_Name").ToString(); List<Employee> employees = FindUsers(userToFind); if(employees.Count>0) { SetTokenValue("employeeName",employees[0].name); }else { SetTokenValue("employeeName","No employee founded"); } } public static List<Employee> FindUsers(string userToFind) { string domainName = "TOHO_MAIN_HQ"; var employees = new List<Employee>(); Employee employee; // Get the current domain context Domain domain = Domain.GetDomain(new DirectoryContext(DirectoryContextType.Domain, domainName)); // Search for users with display names containing "John" using (DirectorySearcher searcher = new DirectorySearcher()) { // Set the search root to the domain's directory entry searcher.SearchRoot = domain.GetDirectoryEntry(); // Set search filter for users with display names containing "John" var instructionToRun= "(&(objectCategory=user)(displayName=*{" + userToFind + "}*))"; searcher.Filter = instructionToRun; // Use wildcard * to find all users with display names // Specify the attributes to load searcher.PropertiesToLoad.AddRange(new string[] { "samAccountName","givenName", "sn", "mail", "displayName", "department", "title", "manager" }); // Perform the search SearchResultCollection results = searcher.FindAll(); // Display search results if (results.Count > 0) { foreach (SearchResult result in results) { employee = new Employee(); // Retrieve and display user details string displayName = result.Properties.Contains("displayname") ? result.Properties["displayName"][0].ToString() : "Not specified"; employee.name = displayName; string email = result.Properties.Contains("mail") ? result.Properties["mail"][0].ToString() : "Not specified"; employee.email = email; string jobTitle = result.Properties.Contains("title") ? result.Properties["title"][0].ToString() : "Not specified"; employee.jobTitle = jobTitle; string department = result.Properties.Contains("department") ? result.Properties["department"][0].ToString() : "Not specified"; employee.department = department; string managerDisplayName = result.Properties.Contains("manager") ? result.Properties["manager"][0].ToString() : "Not specified"; employee.manager = managerDisplayName=="Not specified"? "Not specified" : FindManagerName(managerDisplayName); var employeeAccountName = result.Properties.Contains("samAccountName") ? result.Properties["samAccountName"][0].ToString() : "Not specified"; employee.staff = FindEmployeesBelowToManager(employeeAccountName, domain); employees.Add( employee ); } } } return employees; } public static List<string> FindEmployeesBelowToManager(string manager, Domain domain) { var staff = new List<string>(); // Create a directory searcher for users using (DirectorySearcher searcher = new DirectorySearcher()) { // Set the search root to the domain's directory entry searcher.SearchRoot = domain.GetDirectoryEntry(); // Set search filter for the username var instructionToRun= "(&(objectCategory=user)(samAccountName={" + manager + "}))"; searcher.Filter = instructionToRun; // Specify the attributes to load searcher.PropertiesToLoad.AddRange(new string[] { "distinguishedName" }); // Perform the search SearchResult result = searcher.FindOne(); if (result != null) { // Retrieve the distinguished name of the user string userDn = result.Properties["distinguishedName"][0].ToString(); // Create a directory searcher for direct reports using (DirectorySearcher directReportsSearcher = new DirectorySearcher()) { // Set the search root to the domain's directory entry directReportsSearcher.SearchRoot = domain.GetDirectoryEntry(); // Set search filter for direct reports instructionToRun= "(&(objectCategory=user)(manager={" + userDn + "}))"; directReportsSearcher.Filter = instructionToRun; // Specify the attributes to load directReportsSearcher.PropertiesToLoad.AddRange(new string[] { "displayName" }); // Perform the search SearchResultCollection directReports = directReportsSearcher.FindAll(); // Display direct reports if (directReports.Count > 0) { //Console.WriteLine("Direct Reports:"); foreach (SearchResult directReport in directReports) { string displayName = directReport.Properties.Contains("displayName") ? directReport.Properties["displayName"][0].ToString() : "Not specified"; //Console.WriteLine($"- {displayName}"); staff.Add(displayName); } } else { //Console.WriteLine("No direct reports found."); } } } //else //{ // Console.WriteLine("User not found."); //} } return staff; } public static string FindManagerName(string managerNameWithComma) { string[] managerSeparatedByComma = managerNameWithComma.Split(','); string[] managerNameWithCN = managerSeparatedByComma[0].ToLower().Split('='); string[] managerName = managerNameWithCN[1].Split(' '); for (int i = 0; i < managerName.Length; i++) { if (string.IsNullOrEmpty(managerName[i]) == false) { managerName[i] = char.ToUpper(managerName[i][0]) + managerName[i].Substring(1); } } return string.Join(" ", managerName); } } public class Employee { public string name { get; set; } public string email { get; set; } public string jobTitle { get; set; } public string department { get; set; } public string manager { get; set; } public List<string> staff { get; set; } } }