Web Services
description
Transcript of Web Services
Web Services
Name
Title
Department
Company
Learning Objectives
Fundamentals of Web Services Be able to create and debug a Web Service
Using the .NET Framework SDK Using Visual Studio.NET
Agenda
Web Services Overview Underlying Technologies Developing a Web Service Consuming Web Services Miscellaneous
Web Services OverviewBusiness Today
CEO challenges Revamp customer service Overhaul supply chain Speed up the decision process
CIO challenges Reorient IT architecture Connect with a limitless number of external
constituents Extend processes to external constituents
Web Services Overview Internet Business Processes Span Companies
Web Services Overview Technology Fabric Must Span Companies Too
Companies, suppliers, partners, and customers must be able to work together Faster than ever before Over the Internet Or risk “death by isolation”
Leverage Internet cost structure
Web Services Overview Drivers
Web Services Overview Alternative Solutions
Distributed computing Web sites (portals)
Web Services Overview Distributed Computing
Client/server model Doesn‘t scale Not secure
Distributed object model Components: packaging and interoperability Remoting: remote method invocation COM, CORBA, Java RMI and EJB
Not Internet-friendly Interoperability issues Tightly coupled: still doesn‘t scale
Web Services Overview Distributed Computing
3-tier Application Architecture Great way to build scalable Web applications
But such applications are silos Integration is an afterthought They can be integrated behind the firewall
Even that can be a problem They do not provide a way to integrate across the
firewall (i.e. over the Internet)
Calendar
News
Finance
Weather
Other
Svcs
Ads
Web Services Overview Portals
No standard way to expose functionality Integration is expensive and error-prone Hard to outsource Not designed to be used outside original scope The problem?
HTML is designed for presentation to people Can’t repurpose it in a general, reliable way Don’t even think about screen scraping
Web Services OverviewPortal Limitations
Web Services Overview What Is a Web Service?
The solution? Web Services! A Web Service exposes functionality to a consumer
Over the Internet or intranet A programmable URL Functions you can call over the Internet
Based on Web standards HTTP, XML, SOAP, WSDL, UDDI
Can be implemented in any language on any platform Black boxes
Component-like, reusable
Web Services Overview What Is a Web Service?
A Web Service combines the best features of distributed computing and portals and eliminates the worst Provides a mechanism for invoking methods remotely Uses Web standards (e.g. HTTP) to do so
Web Services Overview What Is a Web Service?
Web Services allow you to interconnect: Different companies Many/any devices Applications Different clients
Not just browsers
Distribution and integration of application logic Enable the programmable Web
Not just the purely interactive Web Web Services are loosely coupled
New paradigm for Internet development Deliver applications as services Richer, customer-driven experience Continuous delivery of value/bits Third-generation Internet
Web Services Overview What Is a Web Service?
Web Services Overview Evolution of the Web
Generation 1
Static HTML
HTML
Generation 2
Web Applications
HTMLHTML, XML
HTML, XML
Generation 3
Web Services
Web Services Overview Benefits
Everyone Leverage existing infrastructure “Build or buy” development decisions Minimize development time/costs
Enterprises Integration imperative Dynamic, easy B2B relationships
New Web-based businesses Greater personalization New services/new revenue streams Be “everywhere” vs. single destination
Web Services Overview Possibilities
Web Services videos Healthcare Family Business
Web Services
Partner Web Service
Partner Web Service
Data Accessand Storage TierApplication
Business LogicTier Other
Applications
YourCompany.com
Internet + XML
Web Services Overview Application Model
ServiceIntegration
Operations
ServiceDelivery
Development Speed
WebServices Platform
Web Services Overview Sample Web Services
YourCompany.
Com
SOAPWire Formats
WSDLDescription
DiscoDiscovery
Web Services
EmailCalendaring
Instant MessagingNotification
Passport (Authentication)Web Storage System
Credit Card ValidationStock Quotes
Inventory Integration
Agenda
Web Services Overview Underlying Technologies Developing a Web Service Consuming Web Services Miscellaneous
Underlying Technologies XML Is the Glue
Program the Web
XML
Browse the Web
HTML
TCP/IP
Connect the Web
Technology
Innovation
Connectivity PresentationConnecting ApplicationsFTP, E-mail, Gopher
Web Pages Web Services
Underlying TechnologiesOverview
Directoryhttp://www.uddi.org
UDDI
DISCO
WSDL
SOAP
Discoveryhttp://www.ibuyspy.com/ibuyspy.disco
Descriptionhttp://www.ibuyspy.com/ibuyspycs/InstantOrder.asmx?wsdl
Wire Format
Locate a Service
Link to Discovery Document
Request Discovery Document
Return Discovery Document (XML)
Return Service Description (XML)
Return Service Response (XML)
Request Service
Request Service Description
Web
Ser
vice
Clie
nt
UD
DI o
ro
ther
directo
ry service
Web
Service
Underlying TechnologiesOverview
A Web Service Directory allows potential clients to locate relevant Web Services UDDI
Discovery is the process of locating documents about Web Services located on at a given URL DISCO
A Description language defines the format of methods provided by a Web Service WSDL
Underlying TechnologiesOverview
The Web Service Wire Format specifies how specific messages are exchanged HTTP-GET HTTP-POST SOAP
HTTP-GET and HTTP-POST use a minimal HTTP interface to invoke Web Services Limited support for data types
SOAP provides a robust HTTP/XML interface Extensive support for data types
XML is designed to represent and transfer structured data In HTML: <p>Jan 15, 2000 </p> In XML: <OrderDate>Jan 15, 2000</OrderDate>
XML does not display or transform data XML separates data from formatting and transforming HTML and XML are both derived from SGML
In different ways
XML OverviewXML Basics
XML is composed of tags and attributes Tags can be nested
Representing entities, entity properties, and entity hierarchy
<ROOT><Orders OrderID="10643" CustomerID="ALFKI" EmployeeID="6" OrderDate="1997-08-25T00:00:00" RequiredDate="1997-09-22T00:00:00" ShippedDate="1997-09-02T00:00:00" />
</ROOT>
XML OverviewXML Syntax
XML schemas describe the structure of an XML document XML schemas describe the tag and attribute
specifications XML schemas also describe constraints on the
contained text XML schemas and the DTD are mutually exclusive
XML OverviewXML Schemas
A lightweight protocol for exchanging information in a distributed, heterogeneous environment It enables cross-platform interoperability
Interoperable OS, object model, programming language neutral Hardware independent Protocol independent
Works over existing Internet infrastructure
SOAP Overview
Guiding principle: “Invent no new technology” Builds on key Internet standards
SOAP = HTTP + XML Submitted to W3C
The SOAP specification defines: The SOAP message format How to send messages How to receive responses Data encoding
SOAP Overview
Objects-by-reference Distributed garbage collection Bi-directional HTTP
Activation Complicated
Doesn’t try to solve every problem in distributed computing
Can be easily implemented
SOAP SOAP Is Not…
SOAPThe HTTP Aspect
SOAP requests are HTTP POST requests
POST /WebCalculator/Calculator.asmx HTTP/1.1Content-Type: text/xml...SOAPAction: “http://tempuri.org/Add”Content-Length: 386
<?xml version=“1.0”?><soap:Envelope ...> ...</soap:Envelope>
SOAP Message
SOAP Envelope
SOAP Header
SOAP Body
Message Name and Data
Headers
Headers
XML-encoded SOAP message name and data
<Body> contains SOAP message name
Individual headers
<Header> encloses headers
<Envelope> encloses payload
Protocol binding headers
The complete SOAP message
SOAPMessage Structure
SOAPSOAP Message Format
An XML document using the SOAP schema:<?xml version=“1.0”?><soap:Envelope ...> <soap:Header ...> ... </soap:Header> <soap:Body> <Add xmlns=“http://tempuri.org/”> <n1>12</n1> <n2>10</n2> </Add> </soap:Body></soap:Envelope>
SOAPServer Responses
Server replies with a “result” message:HTTP/1.1 200 OK...Content-Type:text/xmlContent-Length: 391
<?xml version=“1.0”?><soap:Envelope ...> <soap:Body> <AddResult xmlns=“http://tempuri.org/”> <result>28.6</result> </AddResult> </soap:Body></soap:Envelope>
SOAPEncoding Complex Data
Data structures are serialized as XML:
<soap:Envelope ...> <soap:Body> <GetStockDataResult xmlns=“http://tempuri.org/”> <result> <Description>Plastic Novelties Ltd</Description> <Price>129</Price> <Ticker>PLAS</Ticker> </result> </GetStockDataRseult> </soap:Body></soap:Envelope>
Builds on HTTP Security HTTPS X.509 certificates
Developers / IT choose which methods to expose explicitly
Does not pass application code Firewall-friendly Type safe
SOAPSecurity and Features
DevelopMentor Inc. Digital Creations IONA Technologies PLC Jetform ObjectSpace Inc. Rockwell Software Inc. SAP Compaq
Microsoft Rogue Wave Software Inc. Scriptics Corp. Secret Labs AB UserLand Software Inc. Zveno Pty. Ltd. IBM Hewlett Packard Intel
SOAPIndustry Support
POST /StockQuote HTTP/1.1Host: www.stockquoteserver.comContent-Type: text/xml; charset="utf-8"Content-Length: nnnnSOAPAction: "Some-URI“
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" SOAP-ENV: encodingStyle = "http://schemas.xmlsoap.org/soap/encoding/"> <SOAP-ENV:Body> <m:GetLastTradePrice xmlns:m="Some-URI"> <symbol>DIS</symbol> </m:GetLastTradePrice> </SOAP-ENV:Body></SOAP-ENV:Envelope>
SOAPExample of a SOAP Request
HTTP/1.1 200 OKContent-Type: text/xml; charset="utf-8"Content-Length: nnnn
<SOAP-ENV:Envelope xmlns:SOAP-ENV= "http://schemas.xmlsoap.org/soap/envelope/" SOAP-ENV: encodingStyle= "http://schemas.xmlsoap.org/soap/encoding/"/> <SOAP-ENV:Body> <m:GetLastTradePriceResponse xmlns:m="Some-URI"> <Price>34.5</Price> </m:GetLastTradePriceResponse> </SOAP-ENV:Body></SOAP-ENV:Envelope>
SOAPExample of a SOAP Response
HTTP/1.1 500 Internal Server ErrorContent-Type: text/xml; charset="utf-8"Content-Length: nnnn
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"> <SOAP-ENV:Body> <SOAP-ENV:Fault> <faultcode> SOAP-ENV: MustUnderstand </faultcode> <faultstring>SOAP Must Understand Error </faultstring> </SOAP-ENV:Fault> </SOAP-ENV:Body></SOAP-ENV:Envelope>
SOAPExample of a SOAP Error
WSDL is an XML format for describing Web Services Methods, arguments, return values
WSDLWeb Services Description Language
Data Schema Low-level typing for message parameters
Message Format of an individual transmission
PortType Group messages into logical operations
Binding Connect a PortType to an implementation (usually SOAP)
Service Define the physical location of an end point
WSDL WSDL Elements
WSDL Example
Demo: http://localhost/…/math.asmx?WSDL
DiscoveryDISCO
Discovery lets you find Web Services A Web site publishes DISCO documents, which
returns the URLs of WSDL descriptions DISCO documents can contain references to other
sites and DISCO documents Dynamic discovery enables trees of directories to be
searched
UDDI
What is UDDI? Universal Description, Discovery, and Integration A registration database for Web Services
Based on SOAP and XML
Marketplace
UDDIThe Vision
Search Portal
Marketplace
Search Portal
Marketplace
Business Users
Advanced Discovery via Portals and Marketplaces
UDDI Registries and Protocol
Technical Users
UDDIFeatures and Services
Can search by business, service, Web Service (tModel), binding
Drill-down query model Use find_X queries to obtain top-level detail –xLists
Obtain detail using a get_xDetail inquiry
Can update/register business information, services, and bindings Secure!
UDDIExamples of Service Types
RosettaNet PIPs Ariba cXML CommerceOne xCBL Custom APIs (e.g., MSInvoice) Service Services
Microsoft Passport Rating Services Home Page
UDDIService Type Registration
Pointer to the specifications describing the service type What programmers read to understand how to use
the service May be any combination of documents or XML
resources (schemas, WSDL, etc.) Identifier for who published the service Identifier for the service type itself
called a tModelKey Used as a unique signature by Web sites that
implement those services
UDDIService Types
UDDI Business Registry
Service TypeRegistrations
Service Type Publishers
Hosted Service Specifications
Documentation
Resources
Schemas, XSLT
WSDL
Others…
Unique Identifier Descriptions URL for Specifications
UDDIBusiness Registration
Holds all of the information in UDDI related to a single business or business unit
It is the “master container” Organization hierarchy not defined in V1
businessKeynameURLdescriptioncontactsbusinessServicesidentifierBagcategoryBag
businessEntitykeyedReference
tModelKeykeyNamekeyValue
keyedReference
tModelKeykeyNamekeyValue
keyedReference
tModelKeykeyNamekeyValue
keyedReference
tModelKeykeyNamekeyValue
businessService
tModelKeyNameDescriptionBindingTemplates
businessService
tModelKeyNameDescriptionBindingTemplates
tModelKeykeyNamekeyValue
Contact
PhoneAddressEmail
tModelKeykeyNamekeyValue
Contact
PhoneAddressEmail
UDDIExample of a Registration
BindingTemplate5E2D412E5-44EE-…http://www.sydneynet/harbour…tModelInstanceDetails
tModelInstanceInfo
4453D6FC-223C-3ED0…
http://www.rosetta.net/catalogPIP
keyedReference
DFE-2B…D-U-N-S9876545231
keyedReference
EE123…NAICS0241722
tModelKeys
businessEntityTB993… Harbour Metalswww.harbourmetals.co.au“Serving Inner Sydney Harbour for …contactsbusinessServicesidentifierBagcategoryBag
23T701e54683nf…Online catalog“Website where you can …BindingTemplates
businessService
872-68914281 King’s Blvd, Sydney, [email protected]
Peter Smythe
UDDISoftware Development Kit
Available from http://uddi.microsoft.com COM components and API for interacting with
the UDDI registry Hides XML and SOAP behind objects
UDDI envelope UDDI message
Sample application UDDI Explorer, written with Visual Basic 6.0
Agenda
Web Services Overview Underlying Technologies Developing a Web Service Consuming Web Services Miscellaneous
Developing a Web Service Basics
Web Service source files Implemented in ASP.NET Similar to Web Forms, but have a .asmx file
extension Lives in a virtual directory Can have a code-behind Can use .NET Framework classes and custom
assemblies and classes
Developing a Web Service Code and Syntax
Codebehind
Inline (in C#)
<%@ WebService Language="c#" Codebehind="MyWebService.cs"
Class="FirstWebService.MathService" %>
<%@ WebService Language=“C#“ Class=“MathService“ %>
using System.Web.Services;public class MathService : WebServices { [WebMethod] public int Add(int num1, int num2) { return num1 + num2; }}
Developing a Web Service Demo
Demo: HelloWorld.asmx Demo: MathService.asmx
Developing a Web Service Tools
Notepad Just create a .asmx file
Visual Studio.NET Create ASP.NET Web Service project
Developing a Web Service Publishing Web Services
Expose Web Services and Web Methods Create a Web Service proxy and an assembly
wsdl.exe Create an assembly Enables developers to program against Web Services
Publishing WSDL contracts and HTML description
Developing a Web Service Discovery of Web Services
.disco file XML-based file containing links to resources Stored in the server‘s root directory Access via URL and Dynamic discovery document Start discovering a URL with wsdl.exe
Disco http://terraserver.microsoft.net
Global directory through UDDI Universal, Discovery, Description and Integration
(http://www.uddi.org)
Visual Studio.NET Automatically creates .disco file
Agenda
Web Services Overview Underlying Technologies Developing a Web Service Consuming Web Services Miscellaneous
Consuming Web ServicesOverview
Locate the desired Web Service UDDI DISCO
Get detailed description of Web Service WSDL
Create a proxy that represents the Web Service Proxy has the same methods/arguments/return
values as the Web Service Application instantiates and uses the proxy as if
it were a local object
Consuming Web ServicesOverview
Web ServiceDeveloper Web Application
Developer
Web Server 1
Service Appasmx .aspx
Web Server 2
Service Application
Proxy Web Form
Consuming Web ServicesOverview
Web Services are URL addressable HTTP request/response
Invoking via: HTTP-GET
Method name and arguments HTTP-POST HTTP-SOAP
XML grammar for: Addressing the Web Service Returning results
Consuming Web Services Invoking: HTTP-GET and POST
HTTP-GET
Result is an XML document
http://localhost//MathService.asmx/Multiply?a=11&b=11
<?xml version="1.0" encoding="utf-8" ?> <int xmlns="http://www.microsoft.com/MathService/">121</int>
Consuming Web Services Invoking: HTTP-GET and POST
HTTP-POST
POST /MathService.asmx/Multiply HTTP/1.1 Host: localhost Content-Type: application/x-www-form-urlencoded Content-Length: length
a=string&b=string
Consuming Web Services Invoking: HTTP-SOAP
XML grammar for WebMethod, Method parameter, results
Supports all standard .NET datatypes and value classes Additionally: classes, structs, datasets
Class and struct marshalling Serialization in XML format
Consuming Web Services Type Marshalling
Using HTTP-GET or HTTP-POST Primitive types Enum types Arrays of primitives and enums By-value only
Consuming Web Services Type Marshalling
Using SOAP Primitive types Enum types Classes and structs DataSet XmlNode Arrays of all of the above By-value and by-reference are supported
Consuming Web ServicesTrying It Out
Request without method name or parameters ASP.NET returns a page listing all methods
Click one of the methods and you can test it out
Specify parameters and Invoke Only for primitive data types
Sample requests/responses
http://localhost/MathService.asmx
http://localhost/MathService.asmx?op=Multiply
Consuming Web ServicesTrying It Out
Request with parameter “WSDL” Formal WSDL description of Web Service XML-based grammar Can be used as input for wsdl.exe
http://localhost/MathService.asmx?WSDL
Consuming Web ServicesDemo
Demo: MathService.asmx
Consuming Web ServicesCreating a Proxy
Use wsdl.exe to generate a proxy
Creates MathService.cs Contains MathService class, derived from SoapHttpClientProtocol in the System.Web.Services.Protocols namespace Or HttpGetClientProtocol or HttpPostClientProtocol
You can instantiate these classes dynamically Proxy embeds URL to the Web Service in the
constructor
wsdl http://localhost/MathService.asmx?WSDL
Consuming Web ServicesDiscovery
Use disco.exe to discover Web Services on a specific machine
disco http://localhost
Consuming Web ServicesUsing Visual Studio.NET
Use Add Web Reference to search UDDI or to discover Web Services given a URL
This builds a proxy, and you can start using the Web Service immediately Visual Studio.NET essentially calls disco.exe and wsdl.exe for you
Agenda
Web Services Overview Underlying Technologies Developing a Web Service Consuming Web Services Miscellaneous
MiscellaneousState Management
Web Services are stateless Use ASP.NET session state mechanism
What is a session? Restricted to a logical application Context in which a user communicates to a server
Functionality Request identification and classification Store data across multiple requests Session events Release of session data
.NET State Server Process
MiscellaneousSecurity Model
Reasons for security Prevent access to areas of your Web server Record and store secure relevant user data
Security configuration Authentication, Authorization, Impersonation
Code Access Security Are you the code you told me you are?
WebClient
OS
ASP.NETAppIIS
.NET
WebService
RMIService
DCOMService
Client
Firewall
Port 80
MiscellaneousHTTP and Firewalls
WebService
Client
WebService
Client
Raw HTTP
SSL
<soap:Body> <AddResult xmlns= ...> <result>28.6</result> </AddResult></soap:Body>
<soap:Body> <AddResult xmlns= ...> <result>28.6</result> </AddResult></soap:Body>
MiscellaneousSecure Sockets Layer
MiscellaneousSecurity Model
Similar to securing a Web site Clients are computers and businesses
Possible options with IIS IPSec Basic Basic over SSL Digest Integrated Client certificates Passport?
Like ASP.NET Web Forms COM+ services
COM+ automatic transactions atomic, consistent, isolated, durable (ACID)
MiscellaneousTransactions
MSMQ Server
SQL Server
Application
COM+transaction context
Web Service
MiscellaneousTransactions
[WebMethod(Transaction= Transaction.Required)]
Transaction modes Supported NotSupported Required RequiresNew
MiscellaneousExecution Model
Synchronous Like any other call to class methods
Asynchronous Split the method into two code blocks
BeginMethodName EndMethodName
CLR determines if operation has finished
MiscellaneousHailStorm
What is HailStorm? A set of Web Services that make it much easier to
integrate existing information Oriented to people, instead of to a specific device,
application, service, or network
MiscellaneousHailStorm Services
myAddress - electronic and geographic address for an identity myProfile - name, nickname, special dates, picture myContacts – electronic relationships/address book myLocation - electronic and geographical location and rendezvous myNotifications – notification subscription, management, and routing myInbox - inbox items like e-mail and voice mail, including existing
mail systems myCalendar – time and task management myDocuments – raw document storage myApplicationSettings - application settings myFavoriteWebSites – favorite URLs and other Web identifiers myWallet - receipts, payment instruments, coupons, and other
transaction records myDevices – device settings, capabilities myServices –services provided for an identity myUsage – usage report for above services
MiscellaneousHailStorm Availability
The initial set of HailStorm services is scheduled to be available in a broad developer beta in late 2001, with full release in 2002.
An SDK for building Web Services using Visual Studio 6.0 Components allowing an ASP page to act as a facade
for a COM object Wizard for generating WSDL descriptions from COM
servers Client-side engine for dynamically creating an
Automation proxy from WSDL
MiscellaneousSOAP Toolkit
Available at http://msdn.microsoft.com/downloads/default.asp?URL=/code/sample.asp?url=/msdn-files/027/001/580/msdncompositedoc.xml
Easily expose COM components as Web Services through SOAP and schemas
Client infrastructure for Visual Studio Focused on one way of creating Web Services
MiscellaneousSOAP Toolkit
Remote Object Proxy Engine (ROPE) A set of COM components you can use to build SOAP
messaging into your application Client-side infrastructure to build Web Services Server side infrastructure Greatly simplifies SOAP programming You can use SOAP without using ROPE
MiscellaneousSOAP Toolkit
Conclusion
Web Services Overview Underlying Technologies Developing a Web Service Consuming Web Services Miscellaneous
Resources
Web Services Essentialshttp://msdn.microsoft.com/library/default.asp?URL=/library/techart/webservicesessentials.htm
SOAPhttp://msdn.microsoft.com/soap/
SOAP Specification http://www.w3.org/TR/SOAP/
Resources
Don Box on SOAP http://msdn.microsoft.com/msdnmag/issues/0300/soap/soap.asp
Introduction to SOAPhttp://www.w3.org/2000/xp/Group/Admin/minutes-oct1100/soap-xp-wg_files/frame.htm
WSDL Specificationhttp://www.w3.org/TR/wsdl/
Resources
A Quick Introduction to WSDLhttp://msdn.microsoft.com/library/default.asp?url=/library/en-us/soap/htm/soap_overview_72b0.asp?frame=true
UDDIhttp://www.uddi.orghttp://uddi.microsoft.com
HailStormhttp://www.microsoft.com/net/hailstorm.asp
Resources
Building Web Services with SOAP and ASP.NEThttp://msdn.microsoft.com/msdnmag/issues/01/02/WebComp/webcomp.asp