Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Example Quick Start Code Begin
- namespace PhoneInformationSample
- {
- using System;
- using System.Linq;
- using System.ServiceModel;
- using System.ServiceModel.Channels;
- using Login;
- using UltiProEmployeePhoneInformation;
- public class Program
- {
- static void Main(string[] args)
- {
- // Setup your user credentials.
- const string userName = "YOUR WEB USER NAME";
- const string password = "YOUR PASSWORD";
- const string userApiKey = "YOUR USER API KEY";
- const string customerApiKey = "YOUR CUSTOMER API KEY";
- // Create a proxy to the login service.
- LoginServiceClient loginClient = null;
- try
- {
- loginClient = new LoginServiceClient("WSHttpBinding_ILoginService");
- // Submit the login request to authenticate the user.
- string message = "";
- string authenticationToken = "";
- AuthenticationStatus loginStatus = loginClient.Authenticate(customerApiKey, password, userApiKey, userName, out message, out authenticationToken);
- if (loginStatus == AuthenticationStatus.Ok)
- {
- // User is authenticated and the authentication token is provided.
- Console.WriteLine("User authentication was successful.\n");
- // Find Employees
- Console.WriteLine("----------Start Find----------");
- FindPhoneInformation(customerApiKey, authenticationToken);
- Console.WriteLine("----------End Find----------\n");
- // Get Phone Information
- Console.WriteLine("----------Start Get----------");
- GetPhoneInformation(customerApiKey, authenticationToken);
- Console.WriteLine("----------End Get----------\n");
- // Update Phone Information
- Console.WriteLine("----------Start Update----------");
- UpdatePhoneInformation(customerApiKey, authenticationToken);
- Console.WriteLine("----------End Update----------\n");
- // Create Alternate Number
- Console.WriteLine("----------Start Create----------");
- CreateAlternateNumber(customerApiKey, authenticationToken);
- Console.WriteLine("----------End Create----------\n");
- // Get Phone Information
- Console.WriteLine("----------Start Get----------");
- GetPhoneInformation(customerApiKey, authenticationToken);
- Console.WriteLine("----------End Get----------\n");
- // Delete Alternate Number
- Console.WriteLine("----------Start Delete----------");
- DeleteAlternateNumber(customerApiKey, authenticationToken);
- Console.WriteLine("----------End Delete----------\n");
- // Get Phone Information
- Console.WriteLine("----------Start Get----------");
- GetPhoneInformation(customerApiKey, authenticationToken);
- Console.WriteLine("----------End Get----------\n");
- }
- else
- {
- // User authentication has failed. Review the message for details.
- Console.WriteLine("User authentication failed: " + message);
- }
- loginClient.Close();
- Console.WriteLine("Press a key to exit");
- Console.ReadKey(true);
- }
- catch (Exception e)
- {
- Console.WriteLine(e);
- }
- finally
- {
- if (loginClient != null)
- {
- loginClient.Close();
- }
- }
- }
- static void FindPhoneInformation(string customerApiKey, string authenticationToken)
- {
- EmployeePhoneInformationClient proxy = null;
- try
- {
- // Create a proxy to the EmployeePhoneInformation service.
- proxy = new EmployeePhoneInformationClient("WSHttpBinding_IEmployeePhoneInformation");
- // Add the headers for the Customer api key and authentication token.
- using (new OperationContextScope(proxy.InnerChannel))
- {
- OperationContext.Current.OutgoingMessageHeaders
- .Add(MessageHeader
- .CreateHeader("UltiProToken",
- "http://www.ultimatesoftware.com/foundation/authentication/ultiprotoken",
- authenticationToken));
- OperationContext.Current.OutgoingMessageHeaders
- .Add(MessageHeader
- .CreateHeader("ClientAccessKey",
- "http://www.ultimatesoftware.com/foundation/authentication/clientaccesskey",
- customerApiKey));
- // Create a query object to find the employees.
- EmployeeQuery query = new EmployeeQuery();
- // Set one or more properties to search.
- query.LastName = "LIKE (ba%)";
- query.FullOrPartTime = "=F";
- // Set paging properties
- query.PageSize = "10";
- query.PageNumber = "1";
- // Search for the employees.
- PhoneInformationFindResponse response = proxy.FindPhoneInformations(query);
- // Check the results of the find to see if there are any errors.
- if (response.OperationResult.HasErrors)
- {
- // Review each error.
- foreach (OperationMessage message in response.OperationResult.Messages)
- {
- Console.WriteLine("Error message: " + message.Message);
- }
- }
- else
- {
- // If employee records are returned,
- // loop through the results and write out the data.
- EmployeePhoneInformation[] employees = response.Results;
- foreach (EmployeePhoneInformation employee in employees)
- {
- Console.WriteLine("Employee: " + employee.FirstName + " " + employee.LastName);
- foreach (PhoneInformation phoneInformation in employee.PhoneInformations)
- {
- Console.WriteLine("\tHome Number: " + phoneInformation.HomeNumber);
- Console.WriteLine("\tWork Number: " + phoneInformation.WorkNumber);
- foreach (AlternateNumber alternateNumber in phoneInformation.AlternateNumbers)
- {
- Console.WriteLine("\tAlternate Number: " + alternateNumber.Number);
- }
- }
- }
- if (employees.Length > 0)
- {
- Console.WriteLine("Find was successful.");
- }
- else
- {
- Console.WriteLine("No employees were found for the provided EmployeeQuery.");
- }
- var pagingInfo = response.OperationResult.PagingInfo;
- Console.WriteLine("\nPaging Information:");
- Console.WriteLine("\tThe employee query returned a total of " + pagingInfo.TotalItems + " records.");
- Console.WriteLine("\tThe employee query returned a total of " + pagingInfo.PageTotal + " pages.");
- Console.WriteLine("\tEach page contains " + pagingInfo.PageSize + " records.");
- Console.WriteLine("\tThe Results contain the records for page " + pagingInfo.CurrentPage + ".");
- }
- }
- }
- catch (Exception e)
- {
- Console.WriteLine(e);
- }
- finally
- {
- if (proxy != null)
- {
- proxy.Close();
- }
- }
- }
- static void GetPhoneInformation(string customerApiKey, string authenticationToken)
- {
- EmployeePhoneInformationClient proxy = null;
- try
- {
- // Create a proxy to the EmployeePhoneInformation service.
- proxy = new EmployeePhoneInformationClient("WSHttpBinding_IEmployeePhoneInformation");
- // Add the headers for the Customer api key and authentication token.
- using (new OperationContextScope(proxy.InnerChannel))
- {
- OperationContext.Current.OutgoingMessageHeaders
- .Add(MessageHeader.CreateHeader("UltiProToken",
- "http://www.ultimatesoftware.com/foundation/authentication/ultiprotoken",
- authenticationToken));
- OperationContext.Current.OutgoingMessageHeaders
- .Add(MessageHeader.CreateHeader("ClientAccessKey",
- "http://www.ultimatesoftware.com/foundation/authentication/clientaccesskey",
- customerApiKey));
- // Define employee whose phone information you want to get.
- EmployeeIdentifier employeeIdentifier = new EmployeeNumberIdentifier
- {
- CompanyCode = "C0013",
- EmployeeNumber = "638945004"
- };
- // Get the phone information.
- PhoneInformationGetResponse response =
- proxy.GetPhoneInformationByEmployeeIdentifier(employeeIdentifier);
- // Check the results of the get to see if there are any errors.
- if (response.OperationResult.HasErrors)
- {
- // Review each error.
- foreach (OperationMessage message in response.OperationResult.Messages)
- {
- Console.WriteLine("Error message: " + message.Message);
- }
- }
- else
- {
- // If we did not get any errors then 1 phone information
- // or no phone information was found.
- if (response.Results.Length > 0)
- {
- // One phone information was found.
- Console.WriteLine("Phone Information:");
- PhoneInformation phoneInformation = response.Results[0];
- Console.WriteLine("\tHome Number: " + phoneInformation.HomeNumber);
- Console.WriteLine("\tWork Number: " + phoneInformation.WorkNumber);
- Console.WriteLine("\tAlternate Numbers: " + phoneInformation.WorkNumber);
- foreach (var alternateNumber in phoneInformation.AlternateNumbers)
- {
- Console.WriteLine("\t\tAlternate Number Id: " + alternateNumber.NumberId);
- Console.WriteLine("\t\tAlternate Number: " + alternateNumber.Number);
- }
- Console.WriteLine("Get was Successful.");
- }
- else
- {
- // No phone information was found for this employee.
- Console.WriteLine(string.Format("No phone information was found for employee with Employee Number = {0} and Company Code = {1}",
- ((EmployeeNumberIdentifier)employeeIdentifier).EmployeeNumber, employeeIdentifier.CompanyCode));
- }
- }
- }
- }
- catch (Exception e)
- {
- Console.WriteLine(e);
- }
- finally
- {
- if (proxy != null)
- {
- proxy.Close();
- }
- }
- }
- static void UpdatePhoneInformation(string customerApiKey, string authenticationToken)
- {
- EmployeePhoneInformationClient proxy = null;
- try
- {
- // Create a proxy to the EmployeePhoneInformation service.
- proxy = new EmployeePhoneInformationClient("WSHttpBinding_IEmployeePhoneInformation");
- // Add the headers for the Customer api key and authentication token.
- using (new OperationContextScope(proxy.InnerChannel))
- {
- OperationContext.Current.OutgoingMessageHeaders
- .Add(MessageHeader.CreateHeader("UltiProToken",
- "http://www.ultimatesoftware.com/foundation/authentication/ultiprotoken",
- authenticationToken));
- OperationContext.Current.OutgoingMessageHeaders
- .Add(MessageHeader.CreateHeader("ClientAccessKey",
- "http://www.ultimatesoftware.com/foundation/authentication/clientaccesskey",
- customerApiKey));
- // Define employee whose phone information you want to update.
- EmployeeIdentifier employeeIdentifier = new EmployeeNumberIdentifier
- {
- CompanyCode = "C0013",
- EmployeeNumber = "638945004"
- };
- // Get the phone information.
- PhoneInformationGetResponse getResponse =
- proxy.GetPhoneInformationByEmployeeIdentifier(employeeIdentifier);
- // Check the results of the get to see if there are any errors.
- if (getResponse.OperationResult.HasErrors)
- {
- // Review each error.
- foreach (OperationMessage message in getResponse.OperationResult.Messages)
- {
- Console.WriteLine("Error message: " + message.Message);
- }
- }
- else
- {
- // If we did not get any errors then 1 phone information
- // or no phone information was found.
- if (getResponse.Results.Length > 0)
- {
- // One phone information was found.
- PhoneInformation phoneInformation = getResponse.Results[0];
- Console.WriteLine("Phone information to be updated was found.");
- // Update phone information.
- phoneInformation.HomeNumber = "2225556677";
- phoneInformation.HomeNumberCountry = "CAN";
- phoneInformation.HomeNumberIsPrivate = true;
- PhoneInformationUpdateResponse updateResponse = proxy.UpdatePhoneInformation(new[] { phoneInformation });
- // Check the results to see if the update was successful.
- if (updateResponse.HasErrors)
- {
- if (updateResponse.OperationResult.HasErrors)
- {
- // Review each operation error.
- foreach (OperationMessage message in updateResponse.OperationResult.Messages)
- {
- Console.WriteLine("Operation Error Message: " + message.Message);
- }
- }
- // Review each result errors.
- foreach (Result result in updateResponse.Results.Where(r => r.HasErrors))
- {
- // Review messages for this result error.
- foreach (OperationMessage message in result.Messages)
- {
- Console.WriteLine("Result " + result.RequestNumber
- + " Error Message: " + message.Message);
- }
- }
- }
- else
- {
- // The update was successful.
- Console.WriteLine("Update was successful.");
- }
- }
- else
- {
- // No phone information was found for this employee.
- Console.WriteLine(string.Format("No phone information was found for employee with Employee Number = {0} and Company Code = {1}",
- ((EmployeeNumberIdentifier)employeeIdentifier).EmployeeNumber, employeeIdentifier.CompanyCode));
- }
- }
- }
- }
- catch (Exception e)
- {
- Console.WriteLine(e);
- }
- finally
- {
- if (proxy != null)
- {
- proxy.Close();
- }
- }
- }
- static void CreateAlternateNumber(string customerApiKey, string authenticationToken)
- {
- EmployeePhoneInformationClient proxy = null;
- try
- {
- // Create a proxy to the EmployeePhoneInformation service.
- proxy = new EmployeePhoneInformationClient("WSHttpBinding_IEmployeePhoneInformation");
- // Add the headers for the Customer api key and authentication token.
- using (new OperationContextScope(proxy.InnerChannel))
- {
- OperationContext.Current.OutgoingMessageHeaders
- .Add(MessageHeader.CreateHeader("UltiProToken",
- "http://www.ultimatesoftware.com/foundation/authentication/ultiprotoken",
- authenticationToken));
- OperationContext.Current.OutgoingMessageHeaders
- .Add(MessageHeader.CreateHeader("ClientAccessKey",
- "http://www.ultimatesoftware.com/foundation/authentication/clientaccesskey",
- customerApiKey));
- // Define employee for whom you want to create an alternate number.
- EmployeeIdentifier employeeIdentifier = new EmployeeNumberIdentifier
- {
- CompanyCode = "C0013",
- EmployeeNumber = "638945004"
- };
- AlternateNumber alternateNumber = new AlternateNumber
- {
- Country = "ARG",
- Number = "4447778899",
- Type = "CEL"
- };
- PhoneInformationCreateResponse response = proxy.CreateAlternateNumber(new[] { alternateNumber }, employeeIdentifier);
- // Check the results to see if the create was successful.
- if (response.HasErrors)
- {
- if (response.OperationResult.HasErrors)
- {
- // Review each operation error.
- foreach (OperationMessage message in response.OperationResult.Messages)
- {
- Console.WriteLine("Operation Error Message: " + message.Message);
- }
- }
- // Review each result errors.
- foreach (Result result in response.Results.Where(r => r.HasErrors))
- {
- // Review messages for this result error.
- foreach (OperationMessage message in result.Messages)
- {
- Console.WriteLine("Result " + result.RequestNumber
- + " Error Message: " + message.Message);
- }
- }
- }
- else
- {
- // The create was successful.
- Console.WriteLine("Create of alternate number was successful.");
- }
- }
- }
- catch (Exception e)
- {
- Console.WriteLine(e);
- }
- finally
- {
- if (proxy != null)
- {
- proxy.Close();
- }
- }
- }
- static void DeleteAlternateNumber(string customerApiKey, string authenticationToken)
- {
- EmployeePhoneInformationClient proxy = null;
- try
- {
- // Create a proxy to the EmployeePhoneInformation service.
- proxy = new EmployeePhoneInformationClient("WSHttpBinding_IEmployeePhoneInformation");
- // Add the headers for the Customer api key and authentication token.
- using (new OperationContextScope(proxy.InnerChannel))
- {
- OperationContext.Current.OutgoingMessageHeaders
- .Add(MessageHeader.CreateHeader("UltiProToken",
- "http://www.ultimatesoftware.com/foundation/authentication/ultiprotoken",
- authenticationToken));
- OperationContext.Current.OutgoingMessageHeaders
- .Add(MessageHeader.CreateHeader("ClientAccessKey",
- "http://www.ultimatesoftware.com/foundation/authentication/clientaccesskey",
- customerApiKey));
- // Define employee for whom you want to delete an alternate number.
- EmployeeIdentifier employeeIdentifier = new EmployeeNumberIdentifier
- {
- CompanyCode = "C0013",
- EmployeeNumber = "638945004"
- };
- // Get the phone information for this employee.
- PhoneInformationGetResponse getResponse =
- proxy.GetPhoneInformationByEmployeeIdentifier(employeeIdentifier);
- // Check the results of the get to see if there are any errors.
- if (getResponse.OperationResult.HasErrors)
- {
- // Review each error.
- foreach (OperationMessage message in getResponse.OperationResult.Messages)
- {
- Console.WriteLine("Error message: " + message.Message);
- }
- }
- else
- {
- // If we did not get any errors then 1 phone information
- // or no phone information was found.
- if (getResponse.Results.Length > 0)
- {
- // One phone information was found.
- PhoneInformation phoneInformation = getResponse.Results[0];
- // Get alternate number to delete from employee's phone information.
- AlternateNumber alternateNumber = null;
- if (phoneInformation.AlternateNumbers.Length > 0)
- {
- // Save alternate number to delete
- alternateNumber = phoneInformation.AlternateNumbers[0];
- Console.WriteLine("Alternate number to be deleted was found:");
- Console.WriteLine("\tAlternate Number Id: " + alternateNumber.NumberId);
- }
- else
- {
- Console.WriteLine("This employee does not have an alternate number to delete.");
- }
- if (alternateNumber != null)
- {
- // Delete alternate number
- PhoneInformationDeleteResponse deleteResponse =
- proxy.DeleteAlternateNumber(new[] { alternateNumber }, employeeIdentifier);
- // Check the results to see if the delete was successful.
- if (deleteResponse.HasErrors)
- {
- if (deleteResponse.OperationResult.HasErrors)
- {
- // Review each operation error.
- foreach (OperationMessage message in deleteResponse.OperationResult.Messages)
- {
- Console.WriteLine("Operation Error Message: " + message.Message);
- }
- }
- // Review each result errors.
- foreach (Result result in deleteResponse.Results.Where(r => r.HasErrors))
- {
- // Review messages for this result error.
- foreach (OperationMessage message in result.Messages)
- {
- Console.WriteLine("Result " + result.RequestNumber
- + " Error Message: " + message.Message);
- }
- }
- }
- else
- {
- // The delete was successful.
- Console.WriteLine("Delete of alternate number was successful.");
- }
- }
- }
- else
- {
- // No phone information was found for this employee.
- Console.WriteLine(
- string.Format(
- "No phone information was found for employee with Employee Number = {0} and Company Code = {1}",
- ((EmployeeNumberIdentifier)employeeIdentifier).EmployeeNumber,
- employeeIdentifier.CompanyCode));
- }
- }
- }
- }
- catch (Exception e)
- {
- Console.WriteLine(e);
- }
- finally
- {
- if (proxy != null)
- {
- proxy.Close();
- }
- }
- }
- }
- }
- // Example Quick Start Code End
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement