Connect SOAP API Developer’s Guide Microsoft .NET Sample Application
Microsoft .NET Sample Application
This section describes the Microsoft .NET sample application available with Xactly Connect. The sample application performs the following function:
- Determining Xactly Incent Object Information
- Determining Xactly Incent Object Information
This sample shows how to use the describeXObject method to retrieve the meta- data associated with the object. You can use the describeXObject method to retrieve the field list, object properties, and data types.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ServiceModel.Channels;
using System.IO;
using System.IO.Compression;
namespace XService {
class DescribeXactlyObject {
static void Main(string[] args) {
DescribeXactlyObject toolkitClient =
new DescribeXactlyObject();
XService.XServiceClient client =
new XService.XServiceClient("DiscoveryService",
"https://www.xactlycorp.com/icm/services/DiscoveryService");
System.Net.ServicePointManager.Expect100Continue = false;
string username = "username";
string password = "password";
XService.LoginResponse response =
client.login(username, password, "Incent");
toolkitClient.log(response);
if (response.authenticated) {
AddressHeader header1 =
AddressHeader.CreateAddressHeader("SessionId",
"urn:Xactly", response.sessionId);
AddressHeader header2 =
AddressHeader.CreateAddressHeader("UserName",
"urn:Xactly", username);
AddressHeader[] headers = new AddressHeader[2];
headers[0] = header1;
headers[1] = header2;
System.ServiceModel.EndpointAddress address =
new System.ServiceModel.EndpointAddress(new
Uri(response.serverUrl), headers);
client = new XService.XServiceClient("DiscoveryService",
address);
XService.UserWSO user = new XService.UserWSO();
XService.XField[] fields = client.describeXObject(user);
for (int i = 0; i < fields.Length; i++) {
XService.XField field = fields[i];
toolkitClient.log(“—– Field —–“); toolkitClient.log(“Name: ” + field.name); toolkitClient.log(“Data Type: ” + field.dataType); toolkitClient.log(“Display Label: ” +field.displayLabel); toolkitClient.log(“Field Length: ” + field.length); toolkitClient.log(“Is Required: ” + field.required); toolkitClient.log(“Is Searchable: ” +field.searchable);
} }
}
public void log(XService.LoginResponse loginResponse) {
if (loginResponse == null)
return;
if (loginResponse.authenticated) {
log("Session Id :" + loginResponse.sessionId);
log("Server URL :" + loginResponse.serverUrl);
} else
log(loginResponse.errorCodes);
}
public void log(XService.ErrorCode errorCode) {
if (errorCode == null)
return;
if (errorCode.code != null)
log("Code :" + errorCode.code);
if (errorCode.reason != null)
log("Reason :" + errorCode.reason);
if (errorCode.stackTrace != null)
log("Stack Trace : " + errorCode.stackTrace);
}
public void log(string message) {
Console.WriteLine(message);
}
}
}
Step 1: Getting an Instance of XService
The first step involves getting an the instance of XService.
XService.XServiceClient client =
new XService.XServiceClient("DiscoveryService",
"https://www.xactlycorp.com/icm/services/DiscoveryService");
Step 2: Logging into the Xactly Connect Server
The next step involves logging into the Xactly Connect Server.
string username = "username";
string password = "password";
XService.LoginResponse response =
client.login(username, password, "Incent");
Step 3: Updating the Session Header
After successful authentication, you need to update the endpoint URL of the service and set the token and username in the session header (used in subsequent operation calls). At this point, you can invoke other operations. Note that you only need to set the endpoint URL and session header once per session.
If you do not update the endpoint URL, subsequent operation calls result in an Operation not supported exception. Similarly, if you do not set the session header, you need to log in again for subsequent operation calls.
AddressHeader header1 =
AddressHeader.CreateAddressHeader("SessionId", "urn:Xactly",
response.sessionId);
AddressHeader header2 = AddressHeader.CreateAddressHeader("UserName",
"urn:Xactly", username);
AddressHeader[] headers = new AddressHeader[2];
headers[0] = header1;
headers[1] = header2;
System.ServiceModel.EndpointAddress address = new
System.ServiceModel.EndpointAddress(new Uri(response.serverUrl),
headers);
client = new XService.XServiceClient("DiscoveryService", address);
Step 4: Extracting the Metadata Information
This step uses the describeXObject method to retrieve the metadata associated with the object, including the data type, display label, length, and whether the object is required and searchable.
XService.UserWSO user = new XService.UserWSO();
XService.XField[] fields = service.describeXObject(user);
for (int i = 0; i < fields.Length; i++) {
XService.XField field = fields[i];
toolkitClient.log("----- Field -----");
toolkitClient.log("Name: " + field.name);
toolkitClient.log("Data Type: " + field.dataType);
toolkitClient.log("Display Label: " + field.displayLabel);
toolkitClient.log("Field Length: " + field.length);
toolkitClient.log("Is Required: " + field.required);
toolkitClient.log("Is Searchable: " + field.searchable);
}
Step 5: Defining Logging Utility Methods
This section of the code defines two utility methods to log the LoginResponse and the ErrorCode, and a single method to write a message to the console.
public void log(XService.LoginResponse loginResponse) { …
}
public void log(XService.ErrorCode errorCode) { …
}
public void log(string message) {
Console.WriteLine(message);
}