You are on page 1of 28

Creating and Using Web Services

Objectives
In this lesson, you will learn to: Identify the need for Web services Identify the enabling technologies in Web services Create a Web service Use a Web service in a Visual Basic .NET local application Use a Web service in a Web application

NIIT

Creating and Using Web Services/Lesson 15/Slide 1 of 28

Creating and Using Web Services


Web Service
 Is similar to a component that provides a specific functionality.  Exposes a number of methods that provide functionality that can be used by one or more applications, regardless of the programming languages, operating systems, and hardware platforms used to develop them.  Functionality can be accessed by applications by using Internet standards, such as HTTP and XML.

NIIT

Creating and Using Web Services/Lesson 15/Slide 2 of 28

Creating and Using Web Services


Web Service (Contd.)
Can be of different types:  One that provides a fundamental functionality, which can be used in multiple applications.  Second that can integrate the existing applications that might have been created using different software and hardware platforms.  Third that can be a means to exchange data in business-to-business transactions.

NIIT

Creating and Using Web Services/Lesson 15/Slide 3 of 28

Creating and Using Web Services


Enabling Technologies Used in Web Services
 A Web service can be developed by using any programming language in .NET suite. However, it requires:  A common data representation format in order to ensure the interoperability of the data exchanged by the client application and the Web service.  A standard method for sending messages from the client application to the Web service and vice versa.  A standard format for describing the Web service.  A mechanism to allow client applications to discover the Web services and their locations.

NIIT

Creating and Using Web Services/Lesson 15/Slide 4 of 28

Creating and Using Web Services


Enabling Technologies Used in Web Services (Contd.)
Requirements are fulfilled by using various standards such as:  eXtensible Markup Language (XML) - Allows data interchange regardless of the hardware and software platform used to develop the application.  Simple Object Access Protocol (SOAP) - Is a standard communication protocol for interchanging information in a structured format in a distributed environment.  Web Services Description Language (WSDL) Is an XML vocabulary that describes the methods that are exposed by a Web service.
NIIT Creating and Using Web Services/Lesson 15/Slide 5 of 28

Creating and Using Web Services


Enabling Technologies Used in Web Services (Contd.)
 Universal Description Discovery and Integration (UDDI) - Is used as a standard mechanism to register and discover a Web service provided by various Web service providers.

NIIT

Creating and Using Web Services/Lesson 15/Slide 6 of 28

Creating and Using Web Services


Just a Minute
What is the difference between a Web service and a component?

NIIT

Creating and Using Web Services/Lesson 15/Slide 7 of 28

Creating and Using Web Services


Problem Statement 15.D.1
The Call Center application needs to provide a facility for various departments to view the status of the queries received from various customers. The organization also plans to provide a facility to its customers to find out the status of their queries through a Web site. For this, a reusable code needs to be written so that both local and Web applications can access the details about queries.

NIIT

Creating and Using Web Services/Lesson 15/Slide 8 of 28

Creating and Using Web Services


Task List
Identify a mechanism for writing reusable code. Identify the methods to be exposed to applications. Create a Web service project. Create the methods to be exposed to applications. Execute the application.

NIIT

Creating and Using Web Services/Lesson 15/Slide 9 of 28

Creating and Using Web Services


Task 1: Identify a mechanism for writing reusable code.
Result: A Web service allows applications to transfer data by using standard protocols and data formats. Therefore, in the given scenario, you can create a Web service that exposes a Web method to access query details.

NIIT

Creating and Using Web Services/Lesson 15/Slide 10 of 28

Creating and Using Web Services


Task 2: Identify the methods to be exposed to applications.
Result: In the given scenario, you need to create a Web service and expose a Web method that takes a query ID as a parameter. The Web method should retrieve the details about the query and populate a DataSet object with the query details. This DataSet object should be returned to the client application that uses the Web service.

NIIT

Creating and Using Web Services/Lesson 15/Slide 11 of 28

Creating and Using Web Services


Task 3: Create a Web service project. Task 4: Create the methods to be exposed to applications.
Code model for Web services  A Web service is composed of two parts, the Web service entry point and the code that provides the functionality to be used by other applications.  The .asmx file serves as the entry point for the Web service.  The .asmx file accesses the code from precompiled assemblies and the code-behind (.vb) file corresponding to the Web service.
NIIT Creating and Using Web Services/Lesson 15/Slide 12 of 28

Creating and Using Web Services


 The code-behind file imports the System.Web.Services namespace, which contains the classes that are required to build and use Web services.  All Web service classes inherit the WebService class, which belongs to the System.Web.Services namespace.  While writing code within the Web service class, you can use the following attributes:
WebService:

Used to provide additional information about the Web methods exposed by a Web service. Used for every method that needs to be exposed for use by other applications.
Creating and Using Web Services/Lesson 15/Slide 13 of 28

WebMethod:

NIIT

Creating and Using Web Services


Task 5: Execute the application.

NIIT

Creating and Using Web Services/Lesson 15/Slide 14 of 28

Creating and Using Web Services


Problem Statement 15.D.2
A form needs to be designed in the Call Center application to display the details about a query. The code for retrieving the details about a query is provided in the GetQueryData Web service. This Web service needs to be used in the Call Center application to enable various departments of Diaz Telecommunications to view the status of queries.

NIIT

Creating and Using Web Services/Lesson 15/Slide 15 of 28

Creating and Using Web Services


Task List
Identify the data to be displayed. Design the user interface. Write the code to display data by using the functionality exposed by the Web service. Execute the application.

NIIT

Creating and Using Web Services/Lesson 15/Slide 16 of 28

Creating and Using Web Services


Task 1: Identify the data to be displayed.
Result: The data to be displayed includes:  Query ID  Date of submission  Customer ID  Employee ID  Response date  Status  Feedback
NIIT Creating and Using Web Services/Lesson 15/Slide 17 of 28

Creating and Using Web Services


Task 2: Design the user interface. Task 3: Write the code to display data by using the functionality exposed by the Web service.
To access the functionality exposed by a Web service, perform the following tasks:  Locate the Web service that provides the functionality required in the application.  Create a proxy class for the Web service.  Reference the proxy class in the application code.  Instantiate the proxy class.

NIIT

Creating and Using Web Services/Lesson 15/Slide 18 of 28

Creating and Using Web Services


Task 4: Execute the application.

NIIT

Creating and Using Web Services/Lesson 15/Slide 19 of 28

Creating and Using Web Services


Just a Minute
2. How can you locate the Web services developed by a Web service provider? 3. Which attribute is used to describe a Web service?

NIIT

Creating and Using Web Services/Lesson 15/Slide 20 of 28

Creating and Using Web Services


ASP.NET
Is a powerful programming framework for the development of enterprise-class Web applications. Is a part of the .NET Framework. Provides access to all the features of the .NET Framework. Therefore, you can develop an ASP.NET Web application by using any of the programming languages provided in . NET, such as Visual Basic .NET and C#.

NIIT

Creating and Using Web Services/Lesson 15/Slide 21 of 28

Creating and Using Web Services


Elements of ASP.NET
User interface - For accepting input and displaying text to a user in an ASP.NET Web application, Web Forms are used. The working of a Web Form is similar to that of a Windows Form except that the user interface is typically rendered in a Web browser. Components For providing reusable code and adding business logic in an ASP.NET Web application, Web services are used. Data - For accessing data stored in a database in an ASP.NET Web application, ADO.NET is used.

NIIT

Creating and Using Web Services/Lesson 15/Slide 22 of 28

Creating and Using Web Services


Web Form
 Allows you to create programmable Web pages that serve as a user interface for your Web application.  Provides a combination of HTML, various Web Form controls, and code. Code provided in a Web Form is executed on a Web server running Internet Information Services (IIS) 5.0.  Can be used to interact with any Web application regardless of the browser or the type of computer used by them.

NIIT

Creating and Using Web Services/Lesson 15/Slide 23 of 28

Creating and Using Web Services


Summary
In this lesson, you learned that: A Web service exposes functionality that can be used by one or more applications, regardless of the programming languages, operating systems, and hardware platforms used to develop them. The functionality exposed by a Web service can be accessed by applications by using Internet standards, such as HyperText Transfer Protocol (HTTP) and eXtensible Markup Language (XML). A Web service can be created using any programming language in .NET suite, such as Visual Basic .NET, Visual C#.NET, and Visual C++.NET.
NIIT Creating and Using Web Services/Lesson 15/Slide 24 of 28

Creating and Using Web Services


Summary (Contd.)
Web services use eXtensible Markup Language for interchanging data in a standard format between different applications. To be able to communicate with each other, a Web service and a client application must agree upon a common protocol. SOAP is a standard communications protocol for interchanging information in a structured format in a distributed environment. To be able to use a Web service, the developers of a client application need to know the methods exposed by the Web service and the parameters to be passed to these methods. Web Services Description Language (WSDL) is a markup language, which is used to describe a Web service.
NIIT Creating and Using Web Services/Lesson 15/Slide 25 of 28

Creating and Using Web Services


Summary (Contd.)
The Universal Description Discovery and Integration (UDDI) initiative is used to allow client applications to discover the Web services provided by various Web service providers. A Web service consists of two parts, the Web service entry point and the code that provides the functionality that is used by other applications. The .asmx file serves as the entry point for the Web service. The WebService attribute is an optional attribute that can be used to provide additional information about the Web methods exposed by a Web service. You must place the WebMethod attribute before the declaration of every method that needs to be exposed for use by other applications.
NIIT Creating and Using Web Services/Lesson 15/Slide 26 of 28

Creating and Using Web Services


Summary (Contd.)
In order to be able to access the functionality exposed by a Web service, you need to perform the following tasks:  Locate the Web service that provides the functionality required in the application.  Create a proxy class for the Web service.  Reference the proxy class in the application code.  Instantiate the proxy class. Visual Studio .NET provides you with an integrated development environment for creating Web applications ranging from traditional Web sites consisting of several HTML pages to sophisticated business-to-business applications that provide Web-based components for performing data interchange between trading partners.
NIIT Creating and Using Web Services/Lesson 15/Slide 27 of 28

Creating and Using Web Services


Summary (Contd.)
 The Web applications developed using Visual Studio.NET are built on ASP.NET, which is a powerful programming framework for the development of enterpriseclass Web applications. ASP.NET is a part of the .NET Framework. It provides access to all features of the .NET Framework. An ASP.NET Web application has the same elements as any other client-server application. These elements are the user interface, components, and data. Web services can be effectively used in both local and Web applications. Using a Web service in an ASP.NET Web application involves the same steps as in the case of a Windows application.
NIIT Creating and Using Web Services/Lesson 15/Slide 28 of 28

You might also like