The purpose of the sample application is to
demonstrate how Oracle Data Provider for .NET(ODP.NET) can be used
in a .NET Web Service. This application also shows how ASP.NET DataGrid
can be used in conjunction with .NET Web Services and ODP.NET.
This ASP.NET sample application shows how one can use Oracle Data Provider
for .NET (ODP.NET) along with .NET Web Services. ODP.NET is a native
driver that offers faster and reliable access to Oracle Database by using
Oracle Native APIs. Thus, any .NET Web Service can effectively query and
retrieve data from Oracle database. In order to demonstrate this, a small
Country Information table has been used. When users visit the main page
of the application they should enter valid Username, Password and connect
string. Users, then are allowed to visit the application page where Country
information is displayed. Country Information is displayed
in a DataGrid. The DataGrid is populated and managed by using a .NET Web
Service. Figure 1.1 explains the architecture of this application.
1.
Visual Basic.NET installed with MS Development Environment 7.0 (MS Visual
Studio .NET) including MS .NET Framework 1.0
2. Microsoft Internet Information Services (IIS)
3. Oracle9i Database
or later running SQL*Net TCP/IP listener (can be downloaded here
)
4. Oracle Data Provider for .NET (can be downloaded here
)
Unzip OdpNetWs.zip using Winzip or command utility
to a suitable directory. Later referred as <Extract_Dir>
Extraction of the zip file results in the creation of 'OdpNetWs'
directory. Refer Description of Sample Files
section for more details.
No special database setup is required. This application prompts for a
Oracle Username, Password and connect string. Once this data is supplied
it creates a table called as ODPNET_WS_COUNTRIES. It inserts 5 rows in
this table.
Note :<Extract_dir> refers
to the directory where you have extracted the sample zip file.
Setup virtual directory
To publish your project
from IIS, a virtual directory needs to be created. A virtual directory
is a shared resource that is identified by an alias that represents
a physical location on a server. Follow the steps given below to create
a virtual directory for the sample.
Go to Start -> Settings -> ControlPanel -> Administrative
Tools -> Internet Service Manger -> Internet Information Services
-> <Site Name> -> Default Web Site. Right click on Default
Web Site -> New -> Virtual Directory.
A Virtual Directory Creation Wizard starts.
Click "Next" on welcome screen.
In the virtual directory alias step, Give an
alias "OdpNetWs" for Web Virtual Directory. Click Next.
Enter full path of the "OdpNetWs"
directory that is created after extracting the sample. To associate
the given alias to this physical location. Click Next.
Ensure the Read, Write and Run Scripts access
permission are set for this virtual directory. Click Next.
Click "Finish", this completes the
creation of Virtual Directory.
After previous step (Step 2) is completed a node by name "OdpNetWs"
will be visible in Default Web Site listing.
Expand "OdpNetWs" node by clicking the
+ sign on the left side.
This will display "src" node inside. Expand
"src" node by clicking the + sign on the left side.
Right click on the "client" node inside
"src" node. From the popup menu select "properties".
"client properties" dialog box will open. Go to the directory
tab. There is a property called as Application name. Click on the "Create"
button. Leave the value unchanged. This value should be "client".
Click "OK" button.
Right click on the "webservice" node
inside "src" node. From the popup menu select "properties".
"webservice properties" dialog box will open. Go to the directory
tab. There is a property called as Application name. Click on the "Create"
button. Leave the value unchanged. This value should be "webservice".
Click "OK" button.
Restart your Web Site. To do this you should Stop
the Web Site and then Start the Web Site.
Build the Web Service
Open Visual Studio .NET and to create a new web
project, click on File-> New->Project->Visual Basic project->ASP.NET
Web Application, Edit the project location field and point it to your
"http://<Server-Name>/OdpNetWs/src/webservice"
directory. Replace Server-Name with appropriate value.
<Server-Name> is the Server Name or IP address as per your IIS
configuration. /OdpNetWs/src/webservice is the directory
where your project will be created. Here, OdpNetWs
is the Virtual directory.
To add the sample application files to your project,
Open Solution Explorer of Visual Studio.NET. Click on Icon bar button
that shows all files.
Right click ODPService.asmx file name and select
"Include In Project".
Ensure that the following
.NET Component References have been added to the project you have created:
System
System.Data
Oracle.DataAccess
System.Web
System.Web.Services
System.XML
To add the above .NET Components
Go to Menu -> View -> Solution Explorer.
Right click on the project you have created,
choose 'Add Reference'.
Choose the above .NET Components from the list
displayed.
Click 'Select', then OK.
The chosen .NET component gets added to the
project.
Right Click ODPService.asmx file and select Build
and Browse. You will be taken to the home page of the Web Service. Please
note down the URL of this Web Service. URL can be seen at the top of
IDE window as http://<Server-Name>/OdpNetWs/src/webservice/ODPService.asmx
Build the client
Create one more new web project, Click on File->
New->Project->Visual Basic project->ASP.NET Web Application,
Edit the project location field and point it to your "http://<Server-Name>/OdpNetWs/src/client"
directory. Replace Server-Name with appropriate value.
<Server-Name> is the Server Name or IP address as per your IIS
configuration. /OdpNetWs/src/client is the directory
where your project will be created. Here, OdpNetWs
is the Virtual directory.
Right click the "client" node in the Solution
explorer and select "Set as StartUp Project".
To add the sample application files to your project,
Open Solution Explorer of Visual Studio.NET. Click on Icon bar button
that shows all files.
Right click GridPage.aspx and select "Include
In Project".
Right click Main.aspx and select "Include In
Project".
To add reference to the
Web Service
Go to Menu -> View -> Solution Explorer
Right click on the project "client"
, choose 'Add Web Reference'.
In the Address field enter the URL of the Web
Service that we created earlier and press Enter key
Example : http://<Server-Name>/OdpNetWs/src/webservice/ODPService.asmx
Click Add Reference button
Rebuild the Solution
Expand the Web References node from Solution Explorer.
Right click and rename the node that refers to
the Web Service that we built in step 12 to "webservice".
(Note: This node does not have any extension)
Go to Menu Build -> Click Rebuild Solution to
rebuild the entire solution.
Right Click Main.aspx in the solution explorer and
select "Set As Start Page".
Run the application
Go to Menu Debug -> Start Without Debugging.
Main page of the application will be opened in browser window.
Enter Username, Password and Connect String of the database user with
connect, resource and table creation privileges. Connect string value
is one of the tnsnames entries in the tnsnames.ora file on the machine
where WebService is running and ODP.NET is installed.
This folder contains images used in
the Readme.html file
OdpNetWs\src\client
GridPage.aspx
This ASP page contains a DataGrid that displays
country information with the help of Web Service
GridPage.aspx.vb
Code behind file. This file has the VB code that
generates and populates ASP.NET controls present in GridPage.aspx
page
Main.aspx
Main page of the application. Displays a form that
accepts Username, password and connect string
Main.aspx.vb
Code behind file. This file has the VB code that
generates and populates ASP.NET controls present in Main.aspx page
*.resx
.NET XML Resource Template (This file is automatically
generated when a Visual Studio Project is created)
OdpNetWs\src\webservice
ODPService.asmx
A .NET Web Service that uses Oracle Data Provider
ODPService.asmx.vb
Web Service implementation. This file has methods
that accept and return DataSet through Web Service. It also has support
methods for database operations like opening, closing connections
and creating table.
*.resx
.NET XML Resource Template (This file is automatically
generated when a Visual Studio Project is created)