예제 #1
0
        private void btnSubmit_Click(object sender, EventArgs e)
        {
            const string UltiProTokenNamespace =
                "http://www.ultimatesoftware.com/foundation/authentication/ultiprotoken";

            const string ClientAccessKeyNamespace =
                "http://www.ultimatesoftware.com/foundation/authentication/clientaccesskey";

            string customerApi = Configuration.Default.API_CustomerKey;
            // Create a proxy to the address service:
            var employeeAddressClient = new EmployeeAddressClient("WSHttpBinding_IEmployeeAddress");

            try
            {
                string query = inputQuery.Text;
                // Add the headers for the Customer API key and authentication token:
                using (new OperationContextScope(employeeAddressClient.InnerChannel))
                {
                    OperationContext.Current.OutgoingMessageHeaders.Add(
                        MessageHeader.CreateHeader(
                            "UltiProToken",
                            UltiProTokenNamespace,
                            sessionToken.Text));

                    OperationContext.Current.OutgoingMessageHeaders.Add(
                        MessageHeader.CreateHeader(
                            "ClientAccessKey",
                            ClientAccessKeyNamespace,
                            customerApi));

                    // Create a query object to find the employees:
                    var employeeQuery = new EmployeeQuery();

                    // Set one or more properties to search:
                    int employeeNumber;
                    if (int.TryParse(query, out employeeNumber))
                    {
                        employeeQuery.EmployeeNumber = "=" + employeeNumber.ToString();
                    }
                    else
                    {
                        employeeQuery.LastName = "LIKE (" + query + "%)";
                        try
                        {
                            if (cboFTPT.SelectedItem.ToString() == "Full Time Employees")
                            {
                                employeeQuery.FullOrPartTime = "=F";
                            }
                            if (cboFTPT.SelectedItem.ToString() == "Part Time Employees")
                            {
                                employeeQuery.FullOrPartTime = "=P";
                            }
                        }
                        catch (Exception) { } // empty value is ok here...

                        if (chkTerminated.Checked)
                        {
                            employeeQuery.Status = "=T";
                        }
                        else
                        {
                            employeeQuery.Status = "=A";
                        }
                    }

                    // Find addresses for employees matching the query criteria:
                    AddressFindResponse addressFindResponse =
                        employeeAddressClient.FindAddresses(employeeQuery);

                    // Check the results of the find to see if there are any errors:
                    if (addressFindResponse.OperationResult.HasErrors)
                    {
                        // Review each error:
                        foreach (OperationMessage message in
                                 addressFindResponse.OperationResult.Messages)
                        {
                            results.Text = "Error: " + message.Message;
                        }
                    }
                    else
                    {
                        //  var pagingInfo = addressFindResponse.OperationResult.PagingInfo;

                        status.Text =
                            "The employee query returned a total of " + addressFindResponse.Results.Count() + " records.";
                        status.BackColor = Color.Yellow; status.ForeColor = Color.Red;
                        // If employee records are returned, loop through the
                        // results and output example data:
                        StringBuilder sb = new StringBuilder();

                        foreach (EmployeeAddress employeeAddress in
                                 addressFindResponse.Results)
                        {
                            foreach (Address address in employeeAddress.Addresses)
                            {
                                sb.AppendLine(employeeAddress.FirstName + " " + employeeAddress.LastName +
                                              " (" + employeeAddress.EmployeeNumber + ")");
                                sb.AppendLine("Address: "
                                              + address.AddressLine1 + ", "
                                              + address.City + ", "
                                              + address.StateOrProvince + ", "
                                              + address.ZipOrPostalCode.Substring(0, 5));
                                sb.AppendLine();
                            }
                        }
                        results.Text = sb.ToString();
                    }
                }

                employeeAddressClient.Close();
            }
            catch (Exception ex)
            {
                results.Text = "Exception: " + ex;
                employeeAddressClient.Abort();
            }
        }
예제 #2
0
        private static void FindAddresses(string token)
        {
            const string UltiProTokenNamespace =
                "http://www.ultimatesoftware.com/foundation/authentication/ultiprotoken";

            const string ClientAccessKeyNamespace =
                "http://www.ultimatesoftware.com/foundation/authentication/clientaccesskey";

            string customerApi = Configuration.Default.API_CustomerKey;

            // Create a proxy to the address service:
            var employeeAddressClient = new EmployeeAddressClient("WSHttpBinding_IEmployeeAddress");

            try
            {
                Console.WriteLine("Type ONE of the following, then press <Enter>:");
                Console.WriteLine(" - an Employee ID number");
                Console.WriteLine(" - a partial last name");
                Console.WriteLine(" - an entire last name");
                Console.WriteLine(); Console.Write("> ");
                string query = Console.ReadLine();
                // Add the headers for the Customer API key and authentication token:
                using (new OperationContextScope(employeeAddressClient.InnerChannel))
                {
                    OperationContext.Current.OutgoingMessageHeaders.Add(
                        MessageHeader.CreateHeader(
                            "UltiProToken",
                            UltiProTokenNamespace,
                            token));

                    OperationContext.Current.OutgoingMessageHeaders.Add(
                        MessageHeader.CreateHeader(
                            "ClientAccessKey",
                            ClientAccessKeyNamespace,
                            customerApi));

                    // Create a query object to find the employees:
                    var employeeQuery = new EmployeeQuery();

                    // Set one or more properties to search:
                    int employeeNumber;
                    if (int.TryParse(query, out employeeNumber))
                    {
                        employeeQuery.EmployeeNumber = "=" + employeeNumber.ToString();
                    }
                    else
                    {
                        employeeQuery.LastName = "LIKE (" + query + "%)";
                        //employeeQuery.FullOrPartTime = "=F";
                        employeeQuery.Status = "=A"; //Active Employees Only
                    }
                    // Set paging properties:
                    employeeQuery.PageSize   = "10";
                    employeeQuery.PageNumber = "1";

                    // Find addresses for employees matching the query criteria:
                    AddressFindResponse addressFindResponse =
                        employeeAddressClient.FindAddresses(employeeQuery);

                    // Check the results of the find to see if there are any errors:
                    if (addressFindResponse.OperationResult.HasErrors)
                    {
                        // Review each error:
                        foreach (OperationMessage message in
                                 addressFindResponse.OperationResult.Messages)
                        {
                            Console.WriteLine("Error message: " + message.Message);
                        }
                    }
                    else
                    {
                        var pagingInfo = addressFindResponse.OperationResult.PagingInfo;

                        Console.WriteLine(
                            "The employee query returned a total of {0} records.",
                            pagingInfo.TotalItems);

                        // If employee records are returned, loop through the
                        // results and output example data:
                        foreach (EmployeeAddress employeeAddress in
                                 addressFindResponse.Results)
                        {
                            foreach (Address address in employeeAddress.Addresses)
                            {
                                Console.WriteLine();
                                Console.WriteLine("Employee Number: " + employeeAddress.EmployeeNumber);
                                Console.WriteLine("Name: {0} {1} Address: {2}, {3}, {4} {5}",
                                                  employeeAddress.FirstName,
                                                  employeeAddress.LastName,
                                                  address.AddressLine1,
                                                  address.City,
                                                  address.StateOrProvince,
                                                  address.ZipOrPostalCode);
                            }
                        }
                    }
                }

                var endInput = Console.ReadKey();
                if (endInput.Key.ToString().ToLower() == "a")
                {
                    Console.Clear();
                }
                FindAddresses(token);
                employeeAddressClient.Close();
            }
            catch (Exception ex)
            {
                Console.WriteLine("Exception: " + ex);
                employeeAddressClient.Abort();
            }
        }