Updating a SharePoint list with external web services data (Part 3)

In part 3 we will be building a simple web service request with C#.NET code.

The first thing we must do is initialize the web proxy client object. To begin using the web service proxy client object that was generated by adding a web reference to the GetEmployeePersonalInfo WSDL, we need to add a reference to its namespace using project namespaces. This can be done by adding the following line to the Program.cs source file.

Now that we have visibility into this namespace, we have access to the GetEmployeePersonalInfoService object which will act as a web service proxy client. To initialize this object, use the following line.

Add the above line to the Main method in the Program class (To simplify the code used in this tutorial, we will not be following object oriented design in the example code).

Authentication

In order to authenticate with the Employease Network, we will need to add a UsernameToken element to our SOAP header that conforms to the WS-I basic security profile. Luckily, we can take advantage of the functionality in the WSE 3.0 add-on to generate this for us.

In order to build a UsernameToken you must have created an ECXML user, a company identifier, and a shared secret password provided by ADP to its customers. The demo web service, however, will accept the following  credentials:

Declare the following static member variables within the Program object.

Import the namespace containing the UsernameToken with the following line:

The WS-I basic security profile Username token will be formed using a combination of the ECXML username and the company identifier (e.g. “[email protected]”, “[email protected]”, etc). The Password element will be a hashed combination of the shared secret, nonce, and a timestamp. The UsernameToken object constructor will handle all of this for us.

The next steps are to create a SecurityHeaderType object and add the serialized UsernameToken to it’s list of headers.

The final step is to associate the security header with the web service proxy client object.

Building the request payload

Now it is time to populate the request payload. Because we are using a “Get” service, we will be sending a filter in our request payload. If we were using an “Add” or a “Change” web service to modify employee data, we would send an EmployeeKey element and a data element used to modify the existing data (e.g. user account info, corp group).

For this tutorial, we will be using the Companies filter. In .NET, this will be represented as an array of company identifiers (strings). For the demo, the company identifiers string has been defined as “openapi” in our static member variables declaration within Program.

Next, we need to create a Request object and apply the filter that we created.

We now have enough information to make our web service call. For the GetEmployeePersonalInfo web service, the result will be an array of EmployeePersonalInfoType objects.

Parsing the response payload

Parsing the response is as simple as iterating through the resulting array (in this case an array of EmployeePersonalInfoTypes) and picking out the necessary data. The code below will expose all values for EmployeePersonalInfoType and display them in a console window.

the screen will shows a space for null values between the hyphens.

Because the demo does not assign values to all the employee objects in the web service, the screen will shows a space for null values between the hyphens. When we start building our application to update the SharePoint list with web service data, we will only be using the fields that return an actual value. In our subsequent blog posts, we will be building a SharePoint list that will receive this data, and writing some code that will populate the list with employees in the ADP web service.

Below is the complete code for the TestAPP console application:

January 19, 2013