In this section, you will create the Web service, which a mobile application will consume. Before moving on to the actual creation of a Web service, we will discuss the database tables that the Web service will use.
Database of Rent-a-Car
The tables in the database of Rent-a-Car are discussed in the following list:
The Reservation Table.
The VehicleTypes Table.
Note?/td>You can use the SQL Server Enterprise Manager to create the stored procedures.
You will now write the code to create the preceding stored procedures. The code for the GetRate stored procedure is as follows:
Now add the code for the Reserve stored procedure as follows:
Then add the code for the GetvType stored procedure:
Note?/td>You can use the GetVType stored procedure when you want to populate a user-interface element, such as a list box with the values of all possible vehicle types. Next, add the code for the Update Reservation stored procedure:
Finally, add the code for the ViewReservation stored procedure. The code for the ViewReservation stored procedure is as follows:
Creating the ASP.NET Web Service
After the stored procedures are created, the next step in creating the Web service is creating an ASP.NET Web service by using Visual Studio .NET. To create an ASP.NET Web service, perform the following steps:
The preceding steps create a framework for a Web service application. Now you can modify the Web service code. In the Service1.asmx file for the Web service, add the declarations for various methods as shown in the following code:
The preceding code adds the declarations for the following methods:
Implementing the MakeReservation() Method
The MakeReservation() method accepts the data required to make a reservation. To do this, the Web method calls the Reserve stored procedure as shown in the following code snippet:
Note?/td>Please note that most of these Web methods access a database by using ADO.NET; therefore, you need to include the following statement in the file:
Implementing the GetRate() Method
The GetRate() method accepts a vehicle type, connects to the database, and retrieves the fare per day for the specified car type. Then the code multiplies the given fare with the number of days for which the reservation is made and returns the total fare. The code for the GetRate() method is shown in the following example:
The preceding code uses the ExecuteScalar() method of the SqlCommand object that returns the value in the first column of the first row of the result set.
Note?/td>In some of the previous chapters, we used the ExecuteReader() method to retrieve data from the database. The ExecuteReader() method returns the result as an object of the SqlDataReader class. However, if you need to retrieve only one value, as in this case, the ExecuteScalar() method is preferred.
Implementing the GetVehicleTypes() Method
The GetVehicleTypes() method returns an array of strings to the client application as shown in the following code:
Implementing the CancelReservation() Method
The CancelReservation() method accepts the name, key (password), and pickup date for a user and deletes the reservation by calling the CancelReservation stored procedure. The code for the CancelReservation() method is as shown:
Implementing the ViewReservation() Method
The ViewReservation() method returns the details of a reservation. To do this, the user needs to specify the customer name and the customer key. The code for the ViewReservation() method is as shown:
Implementing the ModifyReservation() Method
After a reservation is made, you can make changes to it by using the ModifyReservation() method. The code for the ModifyReservation() method is as shown:
Building the Web Service
The final step in the creation of the Web service is to build the project and deploy the Web service. To build the project, either run the application or start Internet Explorer and connect to http:// localhost /rental /servicel.asmx. A list of operations that the Web service supports is displayed, as shown in Figure.
The Operations that the Web Service Supports.
Now click on the GetRate() method, and in the resulting screen, as shown in Figure, specify the vehicle type as Premium and click on the Invoke button. Verify that the Web service returns the correct value.
Invoking a Web Method.
After you have verified that the Web service is working, you will create the mobile application that consumes this Web service.
XML Related Interview Questions
|Soap Tool Interview Questions||HTML Interview Questions|
|PHP Interview Questions||ASP.NET Interview Questions|
|PHP5 Interview Questions||Java Interview Questions|
|CSS Interview Questions||XSLT Interview Questions|
|Java XML Interview Questions||XMLHttpRequest (XHR) Interview Questions|
|ebXML Interview Questions||XML DOM Interview Questions|
|XML-RPC Interview Questions||XSD Interview Questions|
|Soap Web Services Interview Questions||XSL Interview Questions|
|Xml Publisher Interview Questions|
Basics Of Xml
Basics Of Web Services
Introduction To Soap
Introduction To Uddi
Introduction To Wsdl
Creating A Web Service Using The Microsoft Soap Toolkit
Building Web Applications On The .net Platform
Creating An Asp.net Web Service
Creating A Web Service From An Interface
Introduction To The Atl Server
Creating A Web Service Using The Atl Server Library
Design And Creation Of The Knowledge Share Web Service
Introduction To Java Xml Technologies
Developing Java Web Services
Design And Creation Of A Web Service Using The Ibm Toolkit
Introduction To Mobile Applications
Creating A Mobile Application That Consumes A Web Service
Web Services Development With Jdeveloper
Creating Web Services Using Perl
Integration Of Xml Web Services With The Office Xp And Sql
Server 2000 Toolkits
All rights reserved © 2018 Wisdom IT Services India Pvt. Ltd
Wisdomjobs.com is one of the best job search sites in India.