vb .net tutorial - 15

Upload: mathes99994840202

Post on 30-May-2018

227 views

Category:

Documents


0 download

TRANSCRIPT

  • 8/14/2019 VB .net tutorial - 15

    1/28

    Creating and Using Web Services

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

    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

  • 8/14/2019 VB .net tutorial - 15

    2/28

    Creating and Using Web Services

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

    Web Service

    Is similar to a component that provides a specific

    functionality.

    Exposes a number of methods that provide functionality thatcan 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 usingInternet standards, such as HTTP and XML.

  • 8/14/2019 VB .net tutorial - 15

    3/28

    Creating and Using Web Services

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

    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.

  • 8/14/2019 VB .net tutorial - 15

    4/28

    Creating and Using Web Services

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

    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 ensurethe 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.

  • 8/14/2019 VB .net tutorial - 15

    5/28

    Creating and Using Web Services

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

    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.

  • 8/14/2019 VB .net tutorial - 15

    6/28

    Creating and Using Web Services

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

    Enabling Technologies Used in Web Services(Contd.)

    Universal Description Discovery and Integration (UDDI)

    - Is used as a standard mechanism to register anddiscover a Web service provided by various Web

    service providers.

  • 8/14/2019 VB .net tutorial - 15

    7/28

    Creating and Using Web Services

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

    Just a Minute

    What is the difference between a Web service and a

    component?

  • 8/14/2019 VB .net tutorial - 15

    8/28

    Creating and Using Web Services

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

    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.

  • 8/14/2019 VB .net tutorial - 15

    9/28

    Creating and Using Web Services

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

    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.

  • 8/14/2019 VB .net tutorial - 15

    10/28

    Creating and Using Web Services

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

    Task 1: Identify a mechanism for writing reusablecode.

    Result:

    A Web service allows applications to transfer data by usingstandard protocols and data formats. Therefore, in the given

    scenario, you can create a Web service that exposes a Web

    method to access query details.

  • 8/14/2019 VB .net tutorial - 15

    11/28

    Creating and Using Web Services

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

    Task 2: Identify the methods to be exposed toapplications.

    Result:

    In the given scenario, you need to create a Web service andexpose 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 theclient application that uses the Web service.

  • 8/14/2019 VB .net tutorial - 15

    12/28

    Creating and Using Web Services

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

    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) filecorresponding to the Web service.

  • 8/14/2019 VB .net tutorial - 15

    13/28

    Creating and Using Web Services

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

    The code-behind file imports theSystem.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.

    WebMethod: Used for every method that needs tobe exposed for use by other applications.

  • 8/14/2019 VB .net tutorial - 15

    14/28

    Creating and Using Web Services

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

    Task 5: Execute the application.

  • 8/14/2019 VB .net tutorial - 15

    15/28

    Creating and Using Web Services

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

    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.

  • 8/14/2019 VB .net tutorial - 15

    16/28

    Creating and Using Web Services

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

    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.

  • 8/14/2019 VB .net tutorial - 15

    17/28

    Creating and Using Web Services

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

    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

  • 8/14/2019 VB .net tutorial - 15

    18/28

    Creating and Using Web Services

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

    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.

  • 8/14/2019 VB .net tutorial - 15

    19/28

    Creating and Using Web Services

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

    Task 4: Execute the application.

  • 8/14/2019 VB .net tutorial - 15

    20/28

    Creating and Using Web Services

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

    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?

  • 8/14/2019 VB .net tutorial - 15

    21/28

    Creating and Using Web Services

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

    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#.

  • 8/14/2019 VB .net tutorial - 15

    22/28

    Creating and Using Web Services

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

    Elements of ASP.NET

    User interface - For accepting input and displaying text to a

    user in an ASP.NET Web application, Web Formsare 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.

  • 8/14/2019 VB .net tutorial - 15

    23/28

    Creating and Using Web Services

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

    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 Formcontrols, 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 regardlessof the browser or the type of computer used by them.

  • 8/14/2019 VB .net tutorial - 15

    24/28

    Creating and Using Web Services

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

    Summary

    In this lesson, you learned that:

    A Web service exposes functionality that can be used by

    one or more applications, regardless of theprogramming 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, suchas 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, VisualC#.NET, and Visual C++.NET.

  • 8/14/2019 VB .net tutorial - 15

    25/28

    Creating and Using Web Services

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

    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 thesemethods. Web Services Description Language (WSDL) is

    a markup language, which is used to describe a Web

    service.

  • 8/14/2019 VB .net tutorial - 15

    26/28

    Creating and Using Web Services

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

    Summary (Contd.)The Universal Description Discovery and Integration (UDDI)

    initiative is used to allow client applications to discoverthe 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 isused by other applications.

    The .asmx file serves as the entry point for the Web service.

    The WebService attribute is an optional attribute that canbe used to provide additional information about the

    Web methods exposed by a Web service.

    You must place the WebMethod attribute before thedeclaration of every method that needs to be exposed foruse by other applications.

  • 8/14/2019 VB .net tutorial - 15

    27/28

    Creating and Using Web Services

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

    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 functionalityrequired 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 integrateddevelopment environment for creating Web applicationsranging from traditional Web sites consisting of several

    HTML pages to sophisticated business-to-businessapplications that provide Web-based components forperforming data interchange between trading partners.

  • 8/14/2019 VB .net tutorial - 15

    28/28

    Creating and Using Web Services

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

    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 enterprise-

    class 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 asany 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 Webapplication involves the same steps as in the case of a

    Windows application.