Web Services from 10,000 feet Part I

Download Report

Transcript Web Services from 10,000 feet Part I

Web Services from 10,000 feet
Part I
Tom Perkins
NTPCUG CertSIG
XML Web Services
What is an XML Web Service
XML Web Service
Consumer’s view
•An interface
• black box
•Exposes well-defined
methods
• a software
•Call using std Internet
component
Consumer
protocols
• has a global
•Pass parameters in XML
reach
format
•Receive responses in XML
format
Can be application specific, in-house
Examples:
Usually available over Internet
•Microsoft .NET Passport
•Google Web Services
•Amazon Web Services
•B2B, B2C(onsumer) apps
03/23/2007
tom perkins
2
SOAP
• Simple Object Access Protocol (Industry Standard)
• Used by consumers of web services
– Send requests to
– Receive response from
• Protocol - Built on top of HTTP
• It defines an XML grammar used to
– Specify names/methods user wants to invoke
– Define parameters and return values
– Describing types of parameters and return values
• Calls to web service must use SOAP grammar to specify
method and parameters
03/23/2007
tom perkins
5
3
What is WSDL?
• Body of SOAP message is XML – a set of tags for encoding the
parameters for the message
• How does the client know how to set up the XML schema?
• Ans: Web service supplies a description of itself
• Request:
• http://localhost/NorthwindServices/ProductService.asmx?wsdl
• Web service sends back a description (Web Service
Description); schema defined by Web Service Description
Language (WSDL)
• Client can construct a SOAP request
• Visual Studio tools
– Parses WSDL
– Creates proxy object
– Client can use the proxy object to convert method calls into SOAP
requests.
03/23/2007
tom perkins
8
4
More SOAP
• Use SOAP to transfer complex data
structures between client and web service
– Input parameters
– Output parameters
– Return values
• Example
– Class holds info re products in NorthWind
– Many properties – ProductID, Product Name, etc
– We’ll create web method to return an instance of
this class
03/23/2007
tom perkins
5
SOAP Serialization
• Converts class to XML
• Sends serial string across the network
• Class reconstructed from serial string at the
consumer (marshalling)
• Serialization is automatic, largely transparent
• Only public fields and properties can be
marshalled
• Each marshalled item must have both get and
set accesssors
• Class must have a default (no parameters)
constructor
03/23/2007
tom perkins
7
6
DEMO
•
•
•
•
Web Service
Web Consumer to follow
Uses Northwind database
Exposes 2 web methods
– Given Product Name and quantity, calculate
the cost of buying quantity
– Given Product Name, return the details for
that product
03/23/2007
tom perkins
7