Example Application

The sample code shown below illustrates how to use the .NET API.

using System; 
using System.IO; 
using System.Collections; 
using System.Text; 
using System.Data;
using g1client; 

try 
 { 
 //Create Server 
 Server server = new Server(); 

 //Set connect property to the server 
 server.SetConnectionProperty(Server.HOST, "localhost"); 
 server.SetConnectionProperty(Server.PORT, "10119"); 
 server.SetConnectionProperty(Server.CONNECTION_TYPE, "SOCKET"); 
 server.SetConnectionProperty(Server.ACCOUNT_ID, "guest"); 
 server.SetConnectionProperty(Server.ACCOUNT_PASSWORD, ""); 

 //Connect to server 
 server.Connect(); 

 //Get Service From Server 
 Service service = server.GetService("ValidateAddress"); 

 //Create Input Message 
 Message request = new Message(); 

 //Fill dataTable in the input message 
 //Datatable is the .net Framework class 
 DataTable dataTable = request.GetDataTable(); 

 DataColumn column1 = new DataColumn(); 
 column1.DataType = System.Type.GetType("System.String"); 
 column1.ColumnName = "AddressLine1"; 
 dataTable.Columns.Add(column1); 

 DataColumn column2 = new DataColumn(); 
 column2.DataType = System.Type.GetType("System.String"); 
 column2.ColumnName = "City"; 
 dataTable.Columns.Add(column2); 

 DataColumn column3 = new DataColumn(); 
 column3.DataType = System.Type.GetType("System.String"); 
 column3.ColumnName = "StateProvince"; 
 dataTable.Columns.Add(column3); 

 DataRow newRow = dataTable.NewRow(); 
 newRow[0]="4200 Parliament Place"; 
 newRow[1]="Lanham"; 
 newRow[2]="Maryland"; 

 dataTable.Rows.Add(newRow); 
 
 //Set "option" Properties to the Input Message 
 request.PutOption("OutputCasing", "M"); 
 request.PutOption("OutputRecordType", "A"); 
 
 //Process Input Message, return output Message 
 Message reply = service.Process(request); 

 //Disconnect from server 
 server.Disconnect(); 

 //Get the result from the response message 
 DataTable returnDataTable = reply.GetDataTable(); 

 foreach(DataColumn dc in returnDataTable.Columns) 
 { 
 // more code to be added 
 string columnName = dc.ColumnName; 
 } 
 foreach(DataRow dr in returnDataTable.Rows) 
 { 
 for (int col = 0; col < returnDataTable.Columns.Count; col++) 
 { 
 // more code to be added 
 string value = (String)dr[col] ; 
 Console.WriteLine(value); 
 } 
 } 
 } 
 catch (Exception e) 
 { 

 //Error handling 
 Console.WriteLine("Error Ocurred, " + e.ToString()); 
 }