Accessing Oracle9iAS
Java Web Service from a .NET Client
Date: 02-June-2003
Objective
After reading this how-to document you should be able
to get a firm handle on how to access an Oracle9iAS
Java Web Service using a .NET client.
Introduction
This document demonstrates how to call a Java Web
Service from a .NET client. It explains how to create the proxy class
and the client to access the Web Service.
Software Requirements
- Microsoft .NET Framework SDK 1.0a available here
- MS Development Environment 7.0 version (MS Visual Studio .NET) (optional)
Description
Web services are self-contained business operations
that operate over the Internet. They are written to a strict specification
using a set of programming standards and messaging protocols to work together
and interoperate with similar kinds of components.
A Web Service is a software application identified by a URI,
whose interfaces and binding are capable of being defined, described, and discovered
by XML artifacts. A Web Service supports direct interactions with other software
applications using XML based messages and Internet-based products. The main
advantage of Web Services is that they are distributed and can be discovered
& invoked by any type of client over the Internet.
Creating the .NET Client
This How-To explains how to create a .NET client for
an Oracle9iAS Java Web Service. In
this How - To, we will access the Oracle9iAS
DEPT/EMP Java Web Service, running live on OTN and available at the following
URL :
/tech/webservices/htdocs/live/index.html
The WSDL file for the above web service is located at following
URL :
/tech/webservices/htdocs/live/deptemp.wsdl
Steps to Create and Execute the C# Client :
Using Visual Studio .NET
- From the Visual Studio.NET create a new .NET solution using the File
menu.
- In the Solution Explorer, right click on
References
and select Add Web Reference.
- In the window that pops up, supply the location of OTNDeptEmp Web
Service WSDL as follows and click on the green arrow:
/tech/webservices/htdocs/live/deptemp.wsdl
- The WSDL document is displayed in the left pane. Click on the
Add
Reference button when it is enabled. This adds an OTNDeptEmp
Web Service reference to your project.
- Create a new C# class named
Client.cs using
File ->Add New Item.
- Add the code given in
Client.cs
to the above class.
- Build the project using
Build ->Build Solution
menu.
- Execute the client code using
Debug ->Start Without
Debugging menu option.
Using .NET Framework SDK
-
Create a directory named WebServiceClient
and navigate to this directory on the command prompt window.
-
Set PATH system variable to point to .Net Framework SDK
Example :
WebServiceClient>set PATH=<SDKFrameWork>\bin;C:\WINNT\Microsoft.NET\Framework\v1.0.3705;%PATH%
where <SDKFrameWork> is the directory
where your .NET Framework SDK is installed.
- Generate the Web Service proxy class, to access the Web Service, using
WSDL tool provided by the .NET Framework
SDK as follows:
WSDL <options> <URI of Web Service WSDL>
In our case:
WebServiceClient>WSDL /namespace:com.oracle.otn /tech/webservices/htdocs/live/deptemp.wsdl
This generates the proxy class named OTNDeptEmp.cs
with the namespace com.oracle.otn to
access the Web Service. By default the WSDL
tool generates the proxy class code in C#. It also notifies the directory
where the proxy class was created.
-
Create a C# file named Client.cs, in
WebServiceClient directory, to use the
above proxy class. The Client.cs code
can be seen here. Following is the part
of code that accesses various methods exposed by the Web Service using
proxy class:
/*
* This method invokes the Web Service to get the 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 the 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 the department numbers
*/
public static void InvokegetDeptNoArray()
{
// instantiate the proxy class
com.oracle.otn.OTNDeptEmp oTNDeptEmp = new com.oracle.otn.OTNDeptEmp();
// call Web Service method to get the 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 the employee numbers
*/
public static void InvokegetEmpNoArray()
{
// instantiate the proxy class
com.oracle.otn.OTNDeptEmp oTNDeptEmp = new com.oracle.otn.OTNDeptEmp();
// call the Web Service method to get the 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 the proxy class
com.oracle.otn.OTNDeptEmp oTNDeptEmp = new com.oracle.otn.OTNDeptEmp();
// call the Web Service method to get the 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("--------------------------------");
}
|
|
Listing 1
- Compile the proxy and the Client class from the command prompt as
follows :
WebServiceClient>csc *.cs
- Execute the Client program as follows :
WebServiceClient>Client
Resources
Summary
This how-to document explained how to access an Oracle9iAS
Java Web Service using a .NET client.
|