Tải bản đầy đủ (.pdf) (29 trang)

ODP .NET Developer''''s Guide oracle database 10g development with visual studio 2005 phần 9 pps

Bạn đang xem bản rút gọn của tài liệu. Xem và tải ngay bản đầy đủ của tài liệu tại đây (1022.2 KB, 29 trang )

Chapter 8
[ 255 ]
Consuming the Web Service from ASP.NET
Now, we will develop an ASP.NET web application that consumes the web service
developed previously. The following are the steps:
1. Open Visual Studio 2005 environment.
2. Create a new website by going to File | New | Web Site and provide the
information as shown in the following screenshot:
3. Using the Solution Explorer, right-click on the project and go to Add Web
Reference as follows:
Application Development Using ODP.NET
[ 256 ]
4. Browse the Web services on the local machine as shown below (if the web
service is available on your local machine).
5. Select the web service created earlier:
Chapter 8
[ 257 ]
6. Provide the Web reference name as EmpService and click on Add Reference:
7. Drag a GridView control and an ObjectDataSource control on to the web
form and congure the data source of ObjectDataSource (using the smart
tag) as follows:
Application Development Using ODP.NET
[ 258 ]
8. Click Next and provide the SELECT method as getList() as follows:
9. Similarly, provide the UPDATE method as Update(), INSERT method as
Add(), DELETE method as Delete(), and nally click on and nally click on Finish.
Chapter 8
[ 259 ]
10. Using the smart tag of the GridView, congure its properties as follows:
11. Using the Properties window provide the DataKeyNames property of the
GridView as empno.


12. Press F5 to test and execute the application.
Developing Smart Device Applications
Microsoft Windows Mobile Platform is now fully supported with .NET technology.
We can develop and deploy .NET-based applications directly on to smart devices
enabled with Microsoft Windows Mobile operating system. Before proceeding with
developing smart device applications, let us discuss Microsoft Windows Mobile
platform and the devices supporting it.
Introducing Microsoft Windows Mobile
There exist several types of smart devices in the market including Smart Phones,
Pocket PCs, Pocket PC Phones, Tablet PCs, etc. Every smart device is installed with a
mobile-based operating system with respect to the features of the device. One of such
operating systems is Microsoft Windows CE.
Microsoft Windows CE is a small, embedded operating system (runs from ROM)
that has a look and feel similar to Microsoft Windows 95/98. It includes scaled down
versions of Microsoft Excel, Microsoft Word, Microsoft Internet Explorer, etc.
Application Development Using ODP.NET
[ 260 ]
Microsoft Windows Mobile (Windows Mobile in short) is a complete software
platform built on Windows CE. Unlike Windows CE, the Windows Mobile for
Smart Phone or Pocket PC operating systems is specically designed for devices that
require a specialized hardware conguration. The software includes standardized
interfaces and applications that ensure compatibility across hardware designs. The
Pocket PC is the best example device that gets equipped with Microsoft Windows
Mobile operating system.
The Pocket PC runs Windows CE as its core operating system. Pocket PCs come
with mobile versions of Microsoft Ofce applications in addition to Microsoft
Outlook Mobile. Though there are different Pocket PCs, many come with Wi-Fi to
enable you to connect to the Internet when you are near to a wireless hotspot. You
can compose email messages and send them wirelessly or by synchronizing with
your desktop computer.

A Pocket PC Phone is a bit different from an ordinary Pocket PC. You can do
everything with a Pocket PC Phone that you can do with a Pocket PC, but with the
addition of cellular phone capabilities. If you have a Pocket PC Phone, you can access
the Internet through the GPRS service.
A Smart Phone has phone capabilities and comes with a smaller set of applications.
Though you can add third-party software titles to your Smart Phone, the smaller
keypad and screen are designed to give you quick one-handed access to important
data. A Smart Phone is a good choice for business users who need to check email,
keep track of their calendars, and take voice notes.
Microsoft.NET enables us to develop and deploy .NET applications on Microsoft
Windows Mobile-enabled smart devices like Smart Phones, Pocket PCs, Tablet PCs,
etc. To develop for either Smart Phones or Pocket PCs, we need not really buy those
devices. We simply need to have smart device client extensions installed as a part of
Visual Studio 2005 (which automatically installs .NET Compact Edition). When the
extensions are installed, we are provided with few device emulators for developing
and testing .NET-based mobile applications. However, for testing and production, it
is recommended to have physical smart devices.
The next section focuses on developing a simple Pocket PC application, which
consumes the web service developed previously.
Consuming a Web Service from Pocket PC
We have already developed a web service previously. Now, let us make use of the
same web service for the Pocket PC. You need not have a physical Pocket PC in your
hands to test it.
Chapter 8
[ 261 ]
We can simply use existing emulators available as part of Visual Studio 2005. The
following are the steps:
1. Open Visual Studio 2005 Environment.
2. Go to File | New | Project.
3. Select and provide information as shown in the following gure:

4. Add a Web Reference for the web service you created earlier.
Application Development Using ODP.NET
[ 262 ]
5. Drag and drop a DataGrid on to the Pocket PC emulator as shown below:
6. Modify the existing code as follows:
Public Class Form1
Private Sub Form1_Load(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles
MyBase.Load
Me.DataGrid1.DataSource =
(New EmpService.Service).getList.Tables(0)
End Sub
End Class
Chapter 8
[ 263 ]
7. Press F5, and select any Emulator for deployment. The output should look and select any Emulator for deployment. The output should look
like the following:
Summary
In this chapter, we concentrated on real-world application development covering
the aspects of asynchronous and multi-threaded development, web applications
(ASP.NET), web reporting, object-oriented development, web services development,
and smart device (Pocket PC) application development.

Introduction to Oracle
Developer Tools for Visual
Studio 2005
Oracle Developer Tools for Visual Studio is an "add-in" for Microsoft Visual Studio
2003/2005, which helps developers to work with Oracle database and develop
Oracle-based .NET applications without leaving the Visual Studio Environment. You
can download it for free from />tech/windows/odpnet/index.html.

In this chapter, we will mainly focus on the following:
Features of Oracle Developer Tools for Visual Studio
Creating and debugging PL/SQL stored procedures using Visual Studio
Developing applications using the Automatic Code Generation feature of ODT
Developing and deploying .NET CLR stored procedures in Oracle database
using Visual Studio
Features of Oracle Developer Tools
Oracle has released Oracle Developer Tools (ODT in short) for Visual Studio .NET
2003/2005 to provide integrated support for developing .NET applications that
access Oracle databases.
When ODT gets installed, the most important feature we notice is the Oracle
Explorer (available through the View menu of Visual Studio.NET). It allows us to
browse existing Oracle objects (like tables, views, stored procedures, etc.), create or
modify tables using table designer, view or edit data, execute SQL statements, etc.




Introduction to Oracle Developer Tools for Visual Studio 2005
[ 266 ]
Some of the other major features are the following:
Designers and Wizards
Automatic Code Generation
PL/SQL Editor
Stored Procedure Testing
Oracle Data Window
SQL Query Window
Integrated Help System
In this section, we will have a glimpse at the most commonly used features along
with sample screenshots.

Before working with ODT, make sure that you congure your
connection to connect to Oracle database using Oracle client.
Connecting to Oracle from Visual Studio
Using Oracle Explorer
Once ODT is installed on your system, you should be able to observe the Oracle
Explorer option in the View menu as follows:







Chapter 9
[ 267 ]
Oracle Explorer allows you to connect to and work with Oracle database from
within the Visual Studio environment. It is very similar to Server Explorer (in Visual
Studio) except that it works only with Oracle databases.
Once you click on Oracle Explorer, you should be able to see the following:
Using the Oracle Explorer window, you can connect to Oracle database using Add
Connection as follows:
Once you are prompted with the Add Connection dialog box, you can provide your
own connection parameters similar to following:
Introduction to Oracle Developer Tools for Visual Studio 2005
[ 268 ]
Once you hit Test connection, you should see the following message:
Chapter 9
[ 269 ]
After hitting OK twice, you will see scott.xe added to Data Connections. Once
you open the scott.xe tree and further open the Tables folder, you should be able to

view the following:
Introduction to Oracle Developer Tools for Visual Studio 2005
[ 270 ]
Retrieving Oracle Information from Visual
Studio Using ODT
One of the easiest ways to retrieve Oracle table or column information is by using
Oracle Explorer together with the Properties window. The moment we select a
database object, the details will be shown in the properties as follows:
Chapter 9
[ 271 ]
Similarly, when a column is selected, the details get pulled out as follows:
Introduction to Oracle Developer Tools for Visual Studio 2005
[ 272 ]
To retrieve all rows in a table, we can simply right-click on the table and select
Retrieve Data as follows:
That would automatically bring all the rows into the Visual Studio environment
where we can view or modify the information as follows:
Chapter 9
[ 273 ]
If you would like to write your own query, execute it, and view the results, you can
use the Query Window option as follows:
Once the Query Window is opened, you can provide your own query and execute it
as follows:
Introduction to Oracle Developer Tools for Visual Studio 2005
[ 274 ]
Working with Oracle Database Objects from
Visual Studio Using ODT
We can create, modify, and drop different database objects from within the Visual
Studio environment using ODT. All of the most important database objects that are
frequently used by developers are accessible through ODT.

Dealing with Tables, Views, and Sequences Using ODT
You can create a new table by right-clicking on Tables and selecting New Relational
Table as follows:
You can modify the existing table design by selecting Design as follows:
Once a table is opened in Design mode, you can modify all the information
(including columns, constrains, indexes, etc.) visually as follows:
Chapter 9
[ 275 ]
You can create or modify views in Oracle as follows:
Introduction to Oracle Developer Tools for Visual Studio 2005
[ 276 ]
You can also create and work with sequences by right-clicking on the Sequences
folder as follows:
The following screenshot denes a sequence named EMPSEQ, which starts at which starts at 1001
and ends at 2001 with an incremental value of 1:
Chapter 9
[ 277 ]
Very similar to sequences, we can even dene synonyms with the following layout:
Another nice feature of ODT is the support for stored procedures, functions, and
packages. We can straight away create, modify, test, and execute these objects from
within the Visual Studio Environment together with other features like IntelliSense,
automatic script generation, etc.
Creating Stored Procedures Using ODT
You can observe the following sequence of gures to create a stored procedure using
ODT. The following initiates the creation of a new PL/SQL stored procedure:
Introduction to Oracle Developer Tools for Visual Studio 2005
[ 278 ]
The following are the details of the stored procedure being created:
The moment Preview SQL is hit, you will observe the script generation as follows:
Chapter 9

[ 279 ]
The moment we save the stored procedure, the Visual Studio environment
automatically opens the stored procedure for editing (along with automatic code
generation and IntelliSense support) as follows:
Debugging PL/SQL Stored Procedures
from Visual Studio
ODT is tightly integrated with Visual Studio even to the level of debugging PL/
SQL stored procedures. Before using the PL/SQL debugging feature, we need to
congure the database and Visual Studio environment to enable PL/SQL debugging.
Let us start conguring the database rst.
We need to provide a few privileges for user Scott, to allow him to debug PL/SQL
stored procedures. Once he is provided with the privileges, we will create a sample
stored procedure and develop a small Windows (desktop) application, and nally
debug the application together with a PL/SQL stored procedure.

×