Notes
Slide Show
Outline
1
ASP.NET Master Class
  • Paul Litwin
  • Deep Training
  • paull@deeptraining.com


2
Paul Litwin
  • Developer
    • Focus: ASP, ASP.NET, VB, SQL Server…
    • MCSD, Microsoft MVP
  • Trainer & Co-Founder
    • Deep Training
      • www.deeptraining.com
  • Conference Chair
    • Microsoft ASP.NET Connections
  • Author/Editor
    • Editor of asp.netPRO Magazine
      • www.aspnetpro.com
    • Author/co-author of a dozen books, including…
      • ASP.NET for Developers
3
Attribution
  • This session adapted from the Web Services chapters in ASP.NET For Developers
    By Mike Amundsen and Paul Litwin


4
Agenda
  • Understanding the Web Services Model
  • Creating an ASP.NET Web Service
  • WSDL and Web Service Clients
  • Working with Complex Types
  • Creating and Consuming Web Services with Visual Studio .NET
  • Creating an ASP Classic Client with the SOAP Toolkit
5
Understanding the Web Services Model
6
Web Service
  • What is it?
    • A programmable application component accessible via standard Web protocols
    • Built on top of SOAP (Simple Object Access Protocol)
    • Examples: stock quote, weather, and work flow, team collaboration
    • Makes building distributed applications easy

7
Standards Based
  • SOAP (Simple Object Access Protocol)
    • Explicit serialization (HTTP + XML description) protocol used in service exchanges
  • WSDL (Web Service Description Language)
    • XML language 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
8
Web Services (In Practice)
9
Important Point
  • While you can build Web Services using .NET, Web Services are not tied to .NET
  • Web Service standards are guided by W3C and other standards bodies
  • Web Services and their clients can be built with a variety different tools on a vast variety of platforms
  • Web Services == Interoperabilty
10
Creating an ASP.NET Web Service
11
Creating ASP.NET Web Services
  • Author .asmx file containing class & methods
    • Add WebService directive
      <%@ WebService class="class" %>
    • Import System.Web.Services namespace
      • Visual Basic: Imports System.Web.Services
      • C#: using System.Web.Services;
    • Add a class that inherits from WebService class
      • Visual Basic:  : Inherits WebService
      • C#:  : WebService
    • Mark methods with WebMethod attribute
      • Visual Basic: <WebMethod()>
      • C#: [WebMethod()]


12
Hello World Example (helloworld.asmx)
13
Web Service Help Page
  • If you browse to an .asmx page, ASP.NET automatically generates a help page that…
    • describes all the Web Service’s operations (methods)
    • lets you browse the WSDL (Service Description) of the service
    • lets you test the Web Service using a sample form and HTTP GET protocol
14
Adding WebMethod and WebService Attributes
  • WebService (attribute of class)
    • Description – document service
    • Name – change SOAP name for service
    • Namespace – create unique namespace for service
  • WebMethod (attribute of method)
    • Description – document method
    • BufferResponse – set to False to turn off buffering
    • CacheDuration – set to True to cache responses
    • EnableSession – set to True to enable Session support
    • MessageName – change SOAP name for message
    • TransactionOption – set to enable transaction support
15
Attribute Example (wsattrib.asmx)
16
WSDL and Web Service Clients
17
Describing Web Services
  • Web Services Description Language (WSDL)
    • Standard XML language for describing Web Services
    • Submitted to W3C by Microsoft, IBM
      (http://www.w3c.org/TR/wsdl)
    • Replaces SDL (used in .NET Beta 1)
  • WSDL is the key  to creating clients
    • Generated automatically by
      .NET Web Services
18
Deconstructing WSDL
19
Creating an ASP.NET Web Service Client
  • Uses proxy and SOAP protocol to communicate with Web Service
  • Steps
    • Use wsdl utility to create local proxy
    • Compile proxy using vbc (or csc)
      • Place compiled proxy assembly in bin folder of Web
    • Create client
      • Import proxy namespace, code to proxy’s properties and methods
20
Generating & Compiling the Proxy (proxygen.bat)
21
Coding Against the Proxy (wsStringsClient.aspx)
22
Working with Complex Types
23
Returning Complex DataTypes
  • ASP.NET Web Services automatically serialize complex types into XML that can be retrieved by just about any client
  • If using an ASP.NET client, however, complex types will be de-serialized back into original type
24
Web Service that Returns a DataSet (wsDataSet.aspx)
25
What HTML GET Client Sees
Pure XML
26
What ASP.NET Client Sees
ADO.NET DataSet that can be Bound to Grid
27
ASP.NET Client
(wsDataSetClient.aspx)
28
Creating and Consuming Web Services with
Visual Studio .NET
29
Creating a Web Service with VS .NET
  • Create a Project of type ASP.NET Web Service
  • Basic skeleton of Web Service is created for you
  • Add Web Methods and go!
30
Consuming a Web Service with VS .NET
  • Create new ASP.NET Web Application (or Windows Form app or another Web Service app…)
  • Right-click on References in Solution Explorer and select Add Web Reference
    • Enter http address of service in dialog
    • After navigating to service (.asmx), click on enabled Add Reference button
  • Proxy is automatically generated for you
  • Full IntelliSense support for Web Services too
31
Coding Against a Web Service in VS .NET
  • Web Service will added to a namespace using the name of the Web Server (localhost for the local machine)
  • Example of coding against local service


32
Creating an ASP Classic Client with the SOAP Toolkit
33
Creating an ASP Classic Client
  • Unlike ASP.NET, ASP Classic doesn’t know how to talk to Web Services using SOAP
  • So, you can either handle SOAP details yourself using lots and lots of code, or download the Microsoft Soap Toolkit 2.0
  • The toolkit, amongst other things, includes a COM component that serves as a Web Service proxy that you can call from any COM-compliant app, including ASP classic
34
Building ASP Classic Client
  • You use Microsoft Soap Toolkit 2.0 soapClient object to call Web Service
35
ASP Classic Client
  • Steps
    • Download and install Microsoft SOAP Toolkit 2.0
    • Create ASP page
    • Set ClientProperty("ServerHTTPRequest") to True
    • Use soapClient object to call Web Service
36
Summary
  • A Web Service is a programmable application component accessible via standard Web protocols built on top of SOAP
  • You can easily create and consume Web Services using ASP.NET
  • It’s even easier to create and consume Web Services using Visual Studio .NET
  • WSDL is the key to creating Web Service clients
  • Web Services serialize and de-serialize complex data types
  • You can create an ASP Classic Web Service client using the Microsoft SOAP Toolkit