Steps to Call an iService Method
Creating an Instance of an iService

To call a method of a specific iService, you must first write the code to create an instance of the iService in the main project.

For example, to call a method of the Contact iService, you must write the following code to create an instance of the Contact iService:

C# Code to Create an instance of the Contact iService
ContactWebService ContactService = new ContactWebService();

In the above code snippet:

  • ContactWebService is the name of the Web Service class of the Contact iService.

  • ContactService is the instance name for the Contact iService.

Add a Method to Generate the Username Token Information

You can use the following method to generate Username Token information. The User token information is used to authenticate the user during the iService calls.

C# Code Method to Generate Username Token Information
public UsernameToken getUserToken(string userName, string password) 
{ 
UsernameToken userToken = new UsernameToken(userName, password, PasswordOption.SendPlainText); 
System.Xml.XmlDocument doc = new System.Xml.XmlDocument(); 
System.Xml.XmlElement TalismaSession = doc.CreateElement("TalismaSessionkey"); 
TalismaSession.InnerText = ""; //Pass this values as blank if no session has to be mantained.
userToken.AnyElements.Add(TalismaSession); 
return userToken; 
}

In the above code snippet:

  • userToken stores the login credentials of the user that will be used during the iServices call.

  • userName and password are credentials used during the iServices call.

  • TalismaSessionKey is the Session key used to authenticate the user every time the iService method is called. Pass this value as blank, if no session has to be maintained.

Note Note

This method is used in the samples provided in the Code Samples section.

Generating the Username Token Information

Add the following line of code to obtain the Username token used for iService calls.

C# Code to Generate the Username Token Information
UsernameToken userToken = getUserToken("ParkerRoy", "password");

In the above code snippet:

  • ParkerRoy is the username of the user that will be used to make the iServices call.

  • Password is the password of the user ParkerRoy.

Associating the Username Token with the iServices Instance

Add the following line of code to associate the Username token with the iServices instance:

C# Code to Associate the Username Token with the iServices Instance
ContactService.RequestSoapContext.Security.Tokens.Add(userToken);
ContactService.RequireMtom = false;
Setting the URL of the Web Service

Add the following line of code if you are using an iService URL that is different from the one that was added while adding the Web Reference for the iService.

C# Code to Set Username Token Information
ContactWebService.Url = "http://worldwaves/ContactiService/Contact.asmx";

In the above code snippet:

  • http://worldwaves/ContactiService/Contact.asmx is the URL of the Contact iService available on the computer where iServices is installed.

Calling a Method of an iService

Following is a sample code to call the CreateContact method of the Contact iService to create a Contact with the name Sam and e-mail address Sam@gmail.com.

C# Code to Set Username Token Information
long contactID = -1; 
string error = ""; 
string contactName = "Sam"; 
bool updateReadOnly = false; 
bool bIgnoreMandatory = false; 
long result = 0; 

//Create a Collection for 2 Contact Properties, Name and E-mail, to create a Contact in CampusNexus CRM. 
ContactiService.PropertyInfo[] propertyDataCollection = new ContactiService.PropertyInfo[2]; 

//Create the PropertyInfo for the Name Property of the Contact Object
ContactiService.PropertyInfo namePropertyData = new ContactiService.PropertyInfo(); 
namePropertyData.propertyID = 56; //Here, 56 is the Property ID for the Name Property of the Contact Object.
namePropertyData.propValue = "Sam"; 
propertyDataCollection[0] = namePropertyData; 

//Create the PropertyInfo for the E-mail Property of the Contact Object
ContactiService.PropertyInfo emailPropertyData = new ContactiService.PropertyInfo(); 
emailPropertyData.propertyID = 57;//Here, 57 is the Property ID for the E-mail Property of the Contact Object. 
emailPropertyData.propValue = "Sam@gmail.com"; 
propertyDataCollection[1] = emailPropertyData; 
result = ContactService.CreateContact(contactName, propertyDataCollection, updateReadOnly, bIgnoreMandatory, out contactID, out error);
Complete Code Sample for the CreateContact Method in the Contact iService
C# Code for the CreateContact Method of Talisma CRM Contact iService
public void CreateContactSample() 
{ 
//Creating an Instance of the Talisma CRM Contact iService 
ContactWebService ContactService = new ContactWebService(); 

//Generating the UsernameToken 
UsernameToken userToken = getUserToken("ParkerRoy", "Password"); 

//Associating the Username Token with the Contact iService Instance 
ContactService.RequestSoapContext.Security.Tokens.Add(userToken); 
ContactService.RequireMtom = false; 

//Calling the CreateContact Method of Talisma CRM Contact iService
long contactID = -1; 
string error = ""; 
string contactName = "Sam";
bool updateReadOnly = false; 
bool bIgnoreMandatory = false; 
long result = 0; 

//Create Collection for 2 Properties, Name and E-mail will be used to create the contact. 
ContactiService.PropertyInfo[] propertyDataCollection = new ContactiService.PropertyInfo[2]; 

//Create the PropertyInfo for Contact Name Property 
ContactiService.PropertyInfo namePropertyData = new ContactiService.PropertyInfo(); 
namePropertyData.propertyID = 56; //Here, 56 is the Property ID for the Name Property of the Contact Object. 
namePropertyData.propValue = "Sam"; 
propertyDataCollection[0] = namePropertyData; 

//Create the PropertyInfo for Contact E-mail Property 
ContactiService.PropertyInfo emailPropertyData = new ContactiService.PropertyInfo(); 
emailPropertyData.propertyID = 57;//Here, 57 is the Property ID for the E-mail Property of the Contact Object.  
emailPropertyData.propValue = "Sam@gmail.com"; 
propertyDataCollection[1] = emailPropertyData; 
result = ContactService.CreateContact(contactName, propertyDataCollection, updateReadOnly, bIgnoreMandatory, out contactID, out error);
}