INT422 Internet III Web Programming on Windows - PowerPoint PPT Presentation

1 / 47
About This Presentation
Title:

INT422 Internet III Web Programming on Windows

Description:

Dealer Systems. Ford Central System. Car Parts. Retailer. Canada Post. Week ... Service to connect the Car Parts Retailer to the Dealers, and use Canada Post's ... – PowerPoint PPT presentation

Number of Views:32
Avg rating:3.0/5.0
Slides: 48
Provided by: team61
Category:

less

Transcript and Presenter's Notes

Title: INT422 Internet III Web Programming on Windows


1
INT422 Internet III Web Programming on
Windows
  • Web Services Introduction

2
Agenda
  • Analyzing the Changing Needs of the Internet
  • Introduction to XML Web Services
  • Building XML Web Services in .NET
  • Consuming XML Web Services in .NET

3
The Need for Web Services
  • Growth of the B2B Internet

4
Real-World Programming Problem
  • You are asked to build a system that connects a
    Car Parts Retailer to all the major car dealers
    in Ontario via their corporate networks. The
    system should allow local dealers to find parts,
    place orders, and track those orders via Canada
    Post.

Dealer Systems
Dealer Systems
Dealer Systems
Canada Post
Daimler Central System
GM Central System
Ford Central System
Car Parts Retailer
5
Obstacles to Overcome
  • First, you dont own the Canada Post or Central
    Dealer systems. You MUST follow each of their
    specifications for formatting and transporting
    data
  • Second you will have to constantly allow for
    changes to these specifications. In three months
    one or all of the systems could change
  • Third, you have to communicate securely between
    systems, and not disclose or expose company
    secrets between any of the participants

6
The Ever Changing WWW
  • When it began in the mid-Nineties, the goal of
    the Web was to get static information published
    globally
  • As it matured, this goal evolved into a desire to
    link organizational data with web sites
  • Next came the E-Commerce phenomenon, and
    companies opened their virtual doors to
    customers around the world.

7
Changing WWWmore
  • So where is the web today? Consider some
    statistics from the 2000 US Census
  • 94 of all E-Commerce transactions were
    Business-to-Business (B2B), or about 777 Billion
  • Only 0.9 of total Retail sales were done on-line
    (29 Billion). In 2003 (most recent data) this
    went up, but it is still less than 2
  • Source
  • http//www.census.gov/eos/www/papers/estatstext.pd
    f
  • Question what does this mean?

8
One Possible Answer
  • Companies dont sell to customers on-line, they
    connect and sell to one another on-line (B2B)
  • Therefore, what is needed are not better,
    flashier, more commercially seductive web sites,
    but rather, better mechanisms for connecting
    businesses and organizations
  • The next great challenge for the web is to allow
    systems and organizations to connect to one
    another regardless of the type technology

9
Doesnt this Already Exist?
  • There have been attempts made in the past to
    solve the any-to-any problem just described
  • COM and DCOM in Windows
  • CORBA and RMI in Java
  • None has ever solved the problem totally, because
    they are all, to one degree or another, linked to
    proprietary technologies or standards
  • What made the web work was its reliance on open
    standards HTML, HTTP, TCP/IP...

10
Using what works
  • Proprietary solutions will never solve the
    problems of connecting proprietary systems
  • Companies like Microsoft, IBM, Sun, etc. along
    with the W3C recognized this
  • Together they agreed to build a solution using
    standards like XML, HTTP, and TCP/IP
  • And to do it they created some new standards
    SOAP, WSDL, and UDDI

11
What are XML Web Services?
12
A Few Definitions
  • A class stored on one machine that can be
    accessed on another machine over a network
    (Deitel)
  • An application that listens to requests coming
    to a TCP socket and reacts to the commands each
    request contains (Balena)
  • A platform for building distributed applications
    using software running on different operating
    systems and devices, written using different
    programming languages. (Microsoft)
  • An application that exists in a distributed
    environment, such as the Internet. A Web Service
    accepts a request, performs its function based on
    the request, and returns a response. (Sun)

13
Web Services Important Ideas
  • Remote Objects
  • Web Services are classes that run on a server and
    can be consumed (i.e., used) by a client over a
    network.
  • Internet Based
  • Web Services use standard Internet protocols to
    pass XML messages between the client and server
  • Loosely Coupled
  • Messages are Sent and Received, but no permanent
    connection exists between Web Services and
    Clients
  • No GUI
  • Web Services provide data-only. Programmers
    build GUIs that use the functionality they
    provide.

14
Programmers Perspective
  • Web Services are classes you use in your code.
  • The Web Service class runs on a server, and you
    create a Proxy Class to stand-in for the remote
    class.
  • You use the Proxy Class as if it were the remote
    object. Therefore, your code is no different
    than if the object was actually running on your
    machine.

15
Understanding Web Services
Web Server
Client
Internet HTTP, TCP/IP
SOAP Message
SOAP Message
Web Service Class
Web Service Proxy Class
App Code
16
A Real-World Web Service Example
Java GUI Client running on Linux
.NET Console Application
Internet HTTP, TCP/IP
Car Quotes Web Service
Web Browser Clients
Web Server running ASP.NET Client App
Web Service - http//wavendon.dsdata.co.uk/axis/se
rvices/CarRentalQuotes
17
Web-based and Console Clients
18
ASP.NET XML Web Services
19
Web Programming using .NET
  • ASP.NET is really two technologies in one
  • Web Forms
  • XML Web Services
  • We now know something about Web Forms
  • a way to build graphical Internet applications
    that can be run using a client browser
  • But what about XML Web Services? How do they
    differ? Why have we spent so little time on them?

20
Class Re-use DLLs vs. Web Services
  • When we want to write re-usable classes in .NET
    we compile them into DLLs
  • DLLs must be copied to the machine that will use
    them. We then add a Reference to the DLL, and
    can then access its classes
  • Web Services also contain re-usable classes. But
    they dont get compiled to DLLs that have to be
    copied to the client. Instead we add Web
    References, which link applications across the web

21
What are XML Web Services?
  • First, they are implemented using XML
  • XML is the eXtensible Markup Language
  • an unambiguous hierarchical way to represent data
    using Tags and Attributes (cf. web.config)
  • XML can be parsed exactly by any system that can
    process strings
  • created and maintained by the World Wide Web
    Consortium (W3C)
  • XML is the standard way to represent data today

22
Web Services use SOAP
  • SOAP is the Simple Object Access Protocol, and is
    a standardized platform independent way to make
    remote procedure calls using XML
  • Web Services receive and send SOAP Messages.
    These are XML formatted strings that contain data
    and information about that data (i.e., metadata
    like type information)
  • Most programmers wont work with SOAP directly.
    You can learn SOAP later if you want to use Web
    Services in advanced ways

23
Web Service Clients use WSDL
  • In order for a client to use a Web Service, the
    client must know how the Web Service works
  • What methods are available?
  • Which types does it return?
  • All this information is contained in another XML
    file called a WSDL file, short for Web Services
    Description Language
  • Again, .NET will automatically generate this for
    us, so we wont dig too deeply into WSDL now

24
Building Your FirstASP.NET Web Service
25
Creating the Web Service
  • Web Services are hosted on a web server
  • Instead of a ASP.NET Web Application, choose
    ASP.NET Web Service

26
The WebService class
  • Rather than having an ASPX file, Web Services use
    a GUI-less class (cs) file and a service base
    (.asmx)

27
Web Services are Classes
  • You create your Web Service Class in code.
  • You build a class that Inherits from System.
    Web.Services.WebService
  • Compare to a web form class, which Inherits from
    System.Web.UI.Page
  • Any of the class methods you want remote users
    to be able to call, you mark using the WebMethod
    attribute

28
A Simple Example Adding Machine
  • WebService(Description "Adds two number",
  • Namespace "http//tempuri.org/")
  • WebServiceBinding(ConformsTo
    WsiProfiles.BasicProfile1_1)
  • public class AddMachSvc System.Web.Services.WebS
    ervice
  • public AddMachSvc ()
  • WebMethod(Description "Returns sum of two
    inputs")
  • public int AddTwoNumbers(int one, int two)
  • return one two

29
Adding Machine - Explained
  • Your class begins with a .NET Attribute,
    contained within the characters
  • System.Web.Services.WebService says this is a Web
    Service
  • Description tells remote users what our Web
    Service does
  • Namespace identifies Web Service uniquely using a
    URL (does NOT have to be a real URL-- cf.
    http//tempuri.org)
  • using System.Web.Services
  • using System.Web.Services.Protocols
  • WebService(Description "Adds two number",
  • Namespace "http//tempuri.org/")
  • WebServiceBinding(ConformsTo
    WsiProfiles.BasicProfile1_1)
  • public class AddMachSvc System.Web.Services.WebS
    ervice

30
Adding Machinemore
  • Now you create your class as you normally would
  • Add the WebMethod() attribute to any methods
    you want to be accessible to the outside world
    remotely
  • NOTE you can write non-WebMethod methods too,
    which remote users wont see or be able to use
  • WebMethod(Description "Returns sum of two
    inputs")
  • public int AddTwoNumbers(int one, int two)
  • return one two

31
Testing your Web Service
  • Test your Web Service base (File gt View in
    Browser) and you will see a test web client for
    you automatically. Click the Web Method to test

32
Testing a WebMethod
  • Enter values for the Web Methods arguments and
    click Invoke
  • Notice the SOAP that will be generated is also
    displayed

33
The SOAP Result
  • When you click Invoke, the WebMethod is called
    using the arguments you entered (i.e., 5 and 6).
    The Result is sent back as a SOAP Message
  • This is XML, but you can easily see the answer is
    11, and that it is an Integer

34
Wait a Minute!I thought you said Web
Services had NO GUI?That looks a lot like a GUI!
35
Web Services No GUI?
  • What you saw a was a GUI, yes. But this was a
    Test Client automatically built by Visual
    Studio.NET
  • Web Services require Client Applications to
    consume them
  • You can use .NET, Java, Perl, or any other
    language or development tool that supports Web
    Services running on any operating system

36
Web Service Clients
  • Question Does your Web Service Client have to be
    web-based?
  • Answer NO! You can use ANY client you like, web
    applications being only one of many solutions
  • In .NET you can use any of the different
    application types available to consume web
    services
  • ASP.NET Web Apps .NET Windows Apps
  • Console Apps .NET Win32 Services
  • DLL Libraries Other .NET Web Services

37
Creating a Web Service Client
  • Any .NET application that you want to consume a
    web service needs a Web Reference to the
    appropriate Web Service
  • A Web Reference is similar
  • to a regular Reference,
  • except that it links to a
  • remote class rather than
  • a local DLL

38
Adding a Web Reference
  • Now you must locate or enter the URL to the Web
    Service you wish to consume

39
Web Referencemore
  • A Web Reference is created for you, and with it a
    number of files are added, the most important of
    which is Reference.vb
  • This is the Proxy class that will stand-in for
    the remote object. You instantiate and use this
    class as though it were a normal class. It will
    call the WebMethods of the Web Service for you in
    the background.

40
How about a Web Client?
  • Build a simple ASP.NET GUI to use the
    AddingMachine Web Service, and add a Web
    Reference just as before

btnEquals
txtSecond
txtFirst
41
Web Client Code
  • protected void btnEquals_Click(object sender,
    EventArgs e)
  • // Create an instance of an AddMachSvc
  • AddMachSvc addMachine new AddMachSvc()
  • // Perform service method
  • lblResult.Text addMachine.AddTwoNumbers(
    int.Parse(txtFirst.Text),

  • int.Parse(txtSecond.Text)).ToString()

42
The Running Web Client
43
Just for fun AddingMachine on Java
  • Building a client for Java is also possible, and
    the result of adding 10 and 50 is displayed below
    in the returned SOAP Message

44
Rethinking B2B CommunicationsUsing Web
Services
45
Solution to our Earlier Problem
  • Build a Web Service to connect the Car Parts
    Retailer to the Dealers, and use Canada Posts
    Web Services to track orders

Dealer Systems
Dealer Systems
Dealer Systems
Tracking Web Service
Canada Post Main System
Daimler Central System
GM Central System
Ford Central System
Car Parts Web Service
Car Parts Back-end System
46
Web Services Solution
  • Now you dont have to worry about proprietary
    data formats--everyone will use XML and SOAP
  • The individual Car Companies can build code to
    consume your Web Service and integrate it with
    their dealers systems, even if they dont have
    web-based systems
  • You can access real-time parcel tracking
    information via Canada Posts own Web Services.

47
Question How could you redesignyour
assignment to useWeb Services?What advantages
would there beto doing this, if any?
Write a Comment
User Comments (0)
About PowerShow.com