Building and Using

insidiousbehaviorΑσφάλεια

3 Νοε 2013 (πριν από 3 χρόνια και 11 μήνες)

91 εμφανίσεις

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?


What protocols does it support?


What data types does it use?


Challenges


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)


Explicit serialization (HTTP + XML description)
protocol used in service exchanges


WSDL (Web Service Description Language)


XML document describing the location and
interfaces a particular service supports


the
client's contract


DISCO (Discovery)


XML document describing (URI) of service


UDDI (Universal Description Discovery and
Integration)


Yellow pages directory for services

Discovery

Let me talk to you (SOAP)

Web Services (In Practice)

Design
-
Time or Dynamic

Runtime

http://yourservice.com

HTML or XML with link to WSDL

How do we talk? (WSDL)

http://yourservice.com/?WSDL

XML with service descriptions

http://yourservice.com/svc1

XML/SOAP BODY

Web

Service

Web

Service

Consumer

UDDI

Find a Service

http://www.uddi.org

Link to DISCO or WSDL document

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


Web Service is represented by an URL


Access to common objects: Request,
Session, Application, etc.


The web service emits no UI


SOAP is for applications


However….


Supports multiple protocols


Including SOAP


Extensible…

Demo: Simple and Complex


Demo 1


Writing a simple service


Add


Demo 2


Comparing VB and C#


Fibonacci


Demo 3


Writing a more complex service


Data Access

3 Mandatory additions, 1 optional addition


<%@ WebService class=“[class]" %>


Names the class and/or language used



Imports System.Web.Services


Required namespace




[WebMethod] or <WebMethod()>


Method is ‘web callable’



WebService base class


Access ASP.NET intrinsic objects

.asmx Deconstructed


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)

Protocols

Using Web Services


Proxy characteristics


Classes are strongly typed


Supports both async and sync



Visual Studio.NET


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


Great way to send out of band data


Not part of the body


Similar to HTTP Headers



XML Attributes


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


Simple


Demo 2


Shaping an XML document


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


http://www.asp.net



Books


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