'**************************************************************************
'@author Chandar
'@version 1.0
'Development Environment : MS Visual Studio .Net
'Name of the File : Client.cs
'Creation/Modification History :
' 02-Jun-2003 Created
'
'Overview:
'The purpose of C# class file is to access Java Web Service using a proxy
'class. It defines methods to access different operations on Web Service
'based on user's selection.
'**************************************************************************
using System;
class Client
{
/*
* Main method of the class
*/
public static void Main()
{
// print out the options user can exercise
Console.WriteLine("Select the information you want..");
Console.WriteLine("1 : Get All Department Numbers");
Console.WriteLine("2 : Get Information of a Department");
Console.WriteLine("3 : Get All Employee Numbers");
Console.WriteLine("4 : Get Information of an Employee");
Console.Write("Enter Choice :");
// get the user's choice
string sel =Console.ReadLine();
int selection = int.Parse(sel);
// call appropriate web service method based on user's choice
switch(selection)
{
// get all the department numbers
case 1 : InvokegetDeptNoArray();
break;
// get the information of a particular department
case 2 :
Console.Write("Enter Department No :");
string deptno =Console.ReadLine();
try
{
// check if the input is a valid number
if (int.Parse(deptno)<=0)
{
Console.WriteLine("Invalid Number");
break;
}
}
catch(Exception e)
{
Console.WriteLine("Invalid Number");
break;
}
// call method to get info of a department
InvokegetDeptInfoArray(deptno);
break;
// call method to get employee numbers of all employees
case 3 : InvokegetEmpNoArray();
break;
// get info of a particular employee
case 4 :
// get the employee number from user
Console.Write("Enter Employee No :");
string empno =Console.ReadLine();
try
{
// check if input is a valid number
if (int.Parse(empno)<=0)
{
Console.WriteLine("Invalid Number");
break;
}
}
catch(Exception e)
{
Console.WriteLine("Invalid Number");
break;
}
// invoke method to get employee information
InvokegetEmpInfoArray(empno);
break;
default: Console.WriteLine("Invalid Selection");
break;
}
}
/*
* This method invokes the web service to get information of a particular department
*/
public static void InvokegetDeptInfoArray(string deptno)
{
// instantiate proxy class
com.oracle.otn.OTNDeptEmp oTNDeptEmp = new com.oracle.otn.OTNDeptEmp();
// invoke web service method using proxy
string[] getDeptInfoArrayResult = oTNDeptEmp.getDeptInfoArray(deptno);
//print out the department information
Console.WriteLine("--------------------------------");
Console.WriteLine("Department Info..");
for(int i=0;i<getDeptInfoArrayResult.GetLength(0);i++)
Console.WriteLine(getDeptInfoArrayResult[i]);
Console.WriteLine("--------------------------------");
}
/*
* This method invokes the Web Service to get all department numbers
*/
public static void InvokegetDeptNoArray()
{
// instantiate proxy class
com.oracle.otn.OTNDeptEmp oTNDeptEmp = new com.oracle.otn.OTNDeptEmp();
// call Web Service method to get department numbers
string[] getDeptNoArrayResult = oTNDeptEmp.getDeptNoArray();
// print out all the department numbers
Console.WriteLine("--------------------------------");
Console.WriteLine("Department Numbers..");
for(int i=0;i<getDeptNoArrayResult.GetLength(0);i++)
Console.WriteLine(getDeptNoArrayResult[i]);
Console.WriteLine("--------------------------------");
}
/*
* This method invokes the Web Service to get all employee numbers
*/
public static void InvokegetEmpNoArray()
{
// instantiate proxy class
com.oracle.otn.OTNDeptEmp oTNDeptEmp = new com.oracle.otn.OTNDeptEmp();
// call Web Service method to get employee numbers in an array
string[] getEmpNoArrayResult = oTNDeptEmp.getEmpNoArray();
// print out the employee numbers
Console.WriteLine("--------------------------------");
Console.WriteLine("Employee Numbers..");
for(int i=0;i<getEmpNoArrayResult.GetLength(0);i++)
Console.WriteLine(getEmpNoArrayResult[i]);
Console.WriteLine("--------------------------------");
}
/*
* This method invokes the Web Service to get info of a particular employee
*/
public static void InvokegetEmpInfoArray(string empno)
{
// instantiate proxy class
com.oracle.otn.OTNDeptEmp oTNDeptEmp = new com.oracle.otn.OTNDeptEmp();
// call Web Service method to get information of the employee
string[] getEmpInfoArrayResult = oTNDeptEmp.getEmpInfoArray(empno);
// print out the employee information
Console.WriteLine("--------------------------------");
Console.WriteLine("Employee Info..");
for(int i=0;i<getEmpInfoArrayResult.GetLength(0);i++)
Console.WriteLine(getEmpInfoArrayResult[i]);
Console.WriteLine("--------------------------------");
}
}
|