ASP+ Web Services

Download Report

Transcript ASP+ Web Services

Building and Using
Web Services with
ASP.NET
Rob Howard
Program Manager
.NET Framework Team
Microsoft Corp.
Agenda







Overview
Standards Based
Building Web Services
Using Web Services
Beyond the Basics
Web Service Security
Summary
What is a Web Service?

Browser is the most common tool for
accessing information on the Internet



Web browser is not enough…
Devices, etc.
A web service is programmable
application logic accessible via
standard Web protocols

Programmable…


Available to a variety of clients (platform independent)
Standard protocols…

Network level interoperability
Common Questions/Issues


How do you publish the location of a
web service?
How do you describe a web service?



Challenges



What protocols does it support?
What data types does it use?
Programming model
Understanding of protocols, serialization,
discovery, etc.
Solutions today still have complexities:


Microsoft SOAP Toolkit
IBM (SOAP Toolkit)
Standards Based

SOAP (Simple Object Access Protocol)


WSDL (Web Service Description Language)


XML document describing the location and
interfaces a particular service supports – the
client's contract
DISCO (Discovery)


Explicit serialization (HTTP + XML description)
protocol used in service exchanges
XML document describing (URI) of service
UDDI (Universal Description Discovery and
Integration)

Yellow pages directory for services
Web Services (In Practice)
Find a Service
http://www.uddi.org
UDDI
Link to DISCO or WSDL document
Discovery
Web
Service
Consumer
http://yourservice.com
HTML or XML with link to WSDL
How do we talk? (WSDL)
http://yourservice.com/?WSDL
XML with service descriptions
Let me talk to you (SOAP)
http://yourservice.com/svc1
XML/SOAP BODY
Design-Time or Dynamic
Runtime
Web
Service
ASP.NET Web Services

Goal: Make building web services
easy

Compiled on first request or pre-compiled
First class feature of ASP.NET

File extension is .asmx


Write application logic


Use features of .NET to enable SOAP
We’re doing the interop work…
ASP.NET Web Services

Part of the ASP.NET application model



The web service emits no UI



Web Service is represented by an URL
Access to common objects: Request,
Session, Application, etc.
SOAP is for applications
However….
Supports multiple protocols


Including SOAP
Extensible…
Demo: Simple and Complex

Demo 1 – Writing a simple service


Demo 2 – Comparing VB and C#


Add
Fibonacci
Demo 3 – Writing a more complex service

Data Access
.asmx Deconstructed
3 Mandatory additions, 1 optional addition
 <%@ WebService class=“[class]" %>


Imports System.Web.Services


Required namespace
[WebMethod] or <WebMethod()>


Names the class and/or language used
Method is ‘web callable’
WebService base class

Access ASP.NET intrinsic objects
Protocols

Http-Get / Http-Post


Html forms name/value
SOAP (Simple Object Access Protocol)





Simple, lightweight XML protocol for
exchanging structured and typed
information on the Web
W3C note (May 8, 2000)
Supported by Microsoft, IBM, and others
Data is sent via POST (or M-POST)
Extensible XML document (Envelope,
Encoding Rules, RPC)
Using Web Services

Proxy characteristics



Visual Studio.NET


Classes are strongly typed
Supports both async and sync
Add Web Reference to a Project
WebServiceUtil.exe



Classes can be created in any .NET
language
WSDL file from a given .NET class
Defined server .NET class from an WSDL
Demo: Building Proxies

Demo 1 – Building a Proxy with VS.NET


Data Access
Demo 2 – Building a Proxy with Command line
tool

Data Access
Beyond the Basics

Soap Headers




XML Attributes




Great way to send out of band data
Not part of the body
Similar to HTTP Headers
Shape the XML to the format you need
XmlAttribute, XmlElement, XmlArray
SoapAttribute, SoapElement, SoapArray
Screen Scrape

Turn any HTML site into a web service*
Demo: Beyond the Basics

Demo 1 – Working with SOAP Headers


Demo 2 – Shaping an XML document


Simple
Order Details
Demo 3 – Screen Scraping

Barnes and Noble
Built-in Security Features

Data hiding (encryption):




Supports HTTPS
Use .NET Crypto classes ‘roll your own’
Beta 1 does not support certificates
Authentication / Authorization



Supports Forms authentication
Supports Windows authentication
Supports ‘roll your own’
Design Suggestions





Know and understand the supported
data types
Don't send unnecessary data (such as
an image) when you can send a URL
Eliminate latency in the server first
Use caching where possible
Build the service to be asynchronous if
the potential exists to block other work
Design Suggestions




Handle client errors when the server is
unavailable
Cache data from the service where
possible, rather than requesting the
same data 100 times
Be efficient about the number of
requests for dynamic data - collapse
multiple web service methods into one
Read the SOAP, DISCO, and WSDL
specs
Summary

Building and using web services is .NET

Microsoft provides the leading platform for
building web applications and services



Great support for XML, HTTP, HTML
Full extensibility enables developers to support
the latest protocols
ASP.NET technology makes writing web
services simple




Share application logic
Use existing skills and knowledge
Consistent development framework
Tool support is incredible!
Resources

Microsoft ASP.NET Web Site


Books



http://www.asp.net
Wrox - “Preview of ASP+“
Others definitely on the way
Additional Sites





http://msdn.microsoft.com/
http://www.4guysfromrolla.com/
http://www.asptoday.com
http://www.aspfree.com
http://www.aspng.com/
Web Services Adopters