Presentation is loading. Please wait.

Presentation is loading. Please wait.

Introduction to ASP.NET, Second Edition2 Chapter Objectives.

Similar presentations


Presentation on theme: "Introduction to ASP.NET, Second Edition2 Chapter Objectives."— Presentation transcript:

1

2 Introduction to ASP.NET, Second Edition2 Chapter Objectives

3 Introduction to ASP.NET, Second Edition3 Overview of Web Services Web applications –Consist of a client, the browser, and a Web server Remote Procedure Call (RPC) –Was used to call another application on the Web server Web Service –Part or all of a Web application that is publicly exposed so that other applications can interact with it. The code itself is not exposed, the interface is –Accessible through standard Web protocols –Platform independent

4 Introduction to ASP.NET, Second Edition4 Overview of Web Services (continued) Browser –Is a client of the Web application. –Does not know the Web server communicates with a Web service Web Server = Web Service Client –Delivers content to a browser –Does not know that the Web Service is communicating with any back-end applications or data sources

5 Introduction to ASP.NET, Second Edition5 Overview of Web Services (continued) WSDL Proxy Class –Web Service Description Language (WSDL) Web Service client application –Does not communicate directly with the Web Service –creates a WSDL proxy Class that is used to invoke the Web service Will communicate with the Web service application through a WSDL stub

6 Introduction to ASP.NET, Second Edition6 Overview of Web Services (continued) WSDL stub –Purpose - to make the communication with the Web service application simpler and transparent –Code that communicates between proxy class and Web service application –Knows what can be sent into and out of the Web service application WSDL proxy and stub created: –Manually - WSDL command line utility (wsdl.exe) –Automatically - Visual Studio.NET

7 Introduction to ASP.NET, Second Edition7 Overview of Web Services (continued) Communication Protocol and Message Format Messages and data are: –Sent back and forth across the a TCP/IP network –Formatted using XML standards so both applications can understand them –Modified to be sent over the Internet using HTTP –Packaged in an envelope using Simple Object Access Protocol (SOAP)

8 Introduction to ASP.NET, Second Edition8 Overview of Web Services (continued)

9 Introduction to ASP.NET, Second Edition9 Applying Web Services to Business Applications Scraping –Process of using a program to view a Web site and capture the source code Samples –Stream data - stock quotes or weather forecast –Real-estate database search application –Human Resource Management Web Service –Bookstore Catalogue Web Service –Community Service Directory Web Service

10 Introduction to ASP.NET, Second Edition10 Using Visual Studio.NET to Create and Consume Web Services Web Services - the core of the Microsoft.NET vision –Microsoft and IBM worked together to create the XML Web Services standards Web Services can be created using a variety of developer tools and programming languages Business-to-Business Sample Web Service –Tara Store Creates a Web Service to provides product data –MaryKate’s Housewares Integrates product data into its own Web site

11 Introduction to ASP.NET, Second Edition11 Building and Consuming a Web Service

12 Introduction to ASP.NET, Second Edition12 Building a Web Service Web Service file extentions –.asmx and.asmx.vb for the code behind the page Three major components –Web Service on the server –Web Service client application that calls the Web Service via a Web reference –A WSDL Web Service description document that describes the functionality of the Web Service Import System.Web.Services namespace

13 Introduction to ASP.NET, Second Edition13 Locating Web Services Need to locate the WSDL document –Web Service creates the WDSL document –Contains the information on how to interact with the Web Service, how to format and send data Web Service Discovery Directory –A third-party directory service –Universal Description, Discovery, and Integration (UDDI)

14 Introduction to ASP.NET, Second Edition14 Locating Web Services (continued) Web Discovery Service File –File extension.DISCO –Points to all of the Web Services within your application Obtain URL of WSDL from Web site owner

15 Introduction to ASP.NET, Second Edition15 Locating Web Services (continued)

16 Introduction to ASP.NET, Second Edition16 The Proxy Class Web Service client application –Does not call the Web Service class directly –Uses WSDL to create a proxy class XML-based request and response messages delivered using HTTPGet, HTTPPost, SOAP SOAP –SOAP calls are remote function calls that invoke method executions on Web Service components –Proxy class creates the SOAP envelope –Soap envelope – a wrapper around the messages and provides information about the message format

17 Introduction to ASP.NET, Second Edition17 Web Services Standards and Protocols HTTP protocol – can be used to deliver documents through proxy servers and firewalls –Pass parameters with a QueryString using HTTPGet –HTTPPost passes parameters as a URL-encoded string, which contains form field names and values attached to the body of the message –SOAP default message by which ASP.NET internally calls a Web Service

18 Introduction to ASP.NET, Second Edition18 The SOAP Contract Simple Object Access Protocol (SOAP) –Standard maintained by WC3 –XML-based protocol used for messaging delivery –Language independent and platform independent SOAP message –Is a remote procedure call over HTTP using XML A simple protocol for publishing available services

19 Introduction to ASP.NET, Second Edition19 The SOAP Contract (continued) Soap contract –XML-formatted document called the WSDL –Describes the interface to the Web Service –View the SOAP contract by opening a browser and typing the URL of the Web Service followed by “?WSDL” –Uses the XML language to describe the location and interfaces that a particular service supports WSDL utility looks at the contract and generates the proxy class based on the contract

20 Introduction to ASP.NET, Second Edition20 The SOAP Contract (continued) DISCO (discovery) document –Is not the SOAP contract –A pointer to the location of the Web Services within the Web project –An XML document that examines the SOAP contract to describe the method and data formats within the Web Service –Describes how the proxy class should make calls to the Web Service disco.exe utility to create the discovery document

21 Introduction to ASP.NET, Second Edition21 Creating a Web Service Visual Studio.NET –Generates WSDL document, DISCO document, test Web page WebService keyword – before the class declaration –Use WebService, if import namespace System Web.Services –Namespace property Identifies a unique URL; distinguish your Web Service from others Default domain tempuri.org Replace with your companies domain name –Description property Used to provide information about your Web Service Can use HTML commands –Name property Name displayed in the Web Service home page.

22 Introduction to ASP.NET, Second Edition22 Creating a Web Service (continued) <System.Web.Services.WebService _ (Namespace:="http://tarastore.com/", _ Description:=  " Displaying Data from the  Tara Store Database ", _ Name:="Chapter 11 Web Service")> _ Public Class ServerVariables... End Class

23 Introduction to ASP.NET, Second Edition23 Creating a Web Service (continued) WebMethod –Expose one or more methods or functions –BufferResponse property Store the response on the server until the entire function is processed True will improve your server performance - minimizes communication –CacheDuration property How long to cache results from the Web service - seconds Automatically cache the results for each unique parameter –MessageName property Name for the method displayed in the Web page –Description property Can format the description with HTML

24 Introduction to ASP.NET, Second Edition24 Creating a Web Service (continued) <WebMethod(CacheDuration:=10, _ Description:=  "GetCat() returns the category list  for the main menu.")> _ Public Function WS_GetCat() As DataSet Dim MySQL As String = "SELECT * FROM Categories" Dim objCM1 As New  OleDbDataAdapter(MySQL, OleDbConnection1) Dim objDS1 As New DataSet objCM1.Fill(objDS1, "Categories") Return objDS1 End Function

25 Introduction to ASP.NET, Second Edition25 Creating a Web Service (continued) Create Web Service - Chapter11WebService Copy data files into the project View code in Ch11Products.vb –Connection string, Connection object, 4 functions Save, build solution View CatMenu.aspx to test database connections and the functions Modify Ch11WS_ProductsDS.asmx

26 Introduction to ASP.NET, Second Edition26 Creating a Web Service (continued)

27 Introduction to ASP.NET, Second Edition27 Previewing the Web Service Home Page View the Web Service home page in a browser –http://localhost/Ch11WebService/Ch11WS_ProductsDS.asmxhttp://localhost/Ch11WebService/Ch11WS_ProductsDS.asmx Click the hyperlink GetCatMethod() takes you to URL: –http://localhost/Chapter11WebService/Ch11WS_ProductsDS.as mx?op=GetCat()+Methodhttp://localhost/Chapter11WebService/Ch11WS_ProductsDS.as mx?op=GetCat()+Method Click Invoke button to test GetCatMethod() –XML document returned. XML data within a DataSet element –Top section describes data – bottom section contains the data Go Back, click hyperlink Service Description –View the service contract –Service Description URL - ?WSDL append to Web Service URL –http://localhost/Ch11WebService/Service1.asmx?WSDLhttp://localhost/Ch11WebService/Service1.asmx?WSDL

28 Introduction to ASP.NET, Second Edition28 Creating a Web Service (continued)

29 Introduction to ASP.NET, Second Edition29 Creating a Web Service (continued)

30 Introduction to ASP.NET, Second Edition30 Creating a Web Service (continued)

31 Introduction to ASP.NET, Second Edition31 Creating a Web Service (continued)

32 Introduction to ASP.NET, Second Edition32 Using a Web Service Call Web Services via: –HTTP Get, Post Limit to primitive data types (integers, strings, arrays of primitive data types) –SOAP Send any structure, class or enumerator – DataSet

33 Introduction to ASP.NET, Second Edition33 Using a Web Service (continued) Send information over Internet, packaged in a format that can travel over a TCP/IP network –Serialization - changing an object into a form that can be readily transported over the network –Deserialization - change the string back into the original structure If the document is in XML format –Use LoadXML method of the XML Document Object Model (DOM) to retrieve the XML data

34 Introduction to ASP.NET, Second Edition34 Consuming a Web Service from an ASP.NET Page MaryKate’s Housewares, which wants to distribute Tara Store’s products on its Web site Create Chapter11 Web application –Copy image folder and data files Add Web Reference –http://localhost/Chapter11WebService/Ch11WS_Prod uctsDS.asmxhttp://localhost/Chapter11WebService/Ch11WS_Prod uctsDS.asmx

35 Introduction to ASP.NET, Second Edition35 Consuming a Web Service from an ASP.NET Page (continued)

36 Introduction to ASP.NET, Second Edition36 Consuming a Web Service from an ASP.NET Page (continued)

37 Introduction to ASP.NET, Second Edition37 Consuming a Web Service from an ASP.NET Page (continued)

38 Introduction to ASP.NET, Second Edition38 Consuming a Web Service from an ASP.NET Page (continued) Modify Ch11DisplayProducts.aspx Dim MyDS As New DataSet Dim MyService As  Chapter11.localhost.Chapter11WebService = _ New Chapter11.localhost.Chapter11WebService MyDS = MyService.WS_GetProducts(ProdID) MyProdList.DataSource = _ MyDS.Tables("Products").DefaultView MyProdList.DataBind()

39 Introduction to ASP.NET, Second Edition39 Consuming a Web Service from an ASP.NET Page (continued)

40 Introduction to ASP.NET, Second Edition40 Locating Web Services UDDI - directory service for registering and searching for Web Services Third-party Web Services –www.xmethods.netwww.xmethods.net –www.coldrooster.comwww.coldrooster.com –www.asp.netwww.asp.net –www.gotdotnet.comwww.gotdotnet.com Local Web Services –Discovery document points to Web Services

41 Introduction to ASP.NET, Second Edition41 Locating Web Services (continued)

42 Introduction to ASP.NET, Second Edition42 Locating Web Services (continued)

43 Introduction to ASP.NET, Second Edition43 Securing Web Services Traditional methods –Secure Sockets Layer (SSL) protocol To encrypt data sent using the HTTP protocol –Web Server authentication tools in IIS To change access permissions –Windows NTFS (Windows NT File System) file or directory security To protect Web Service page

44 Introduction to ASP.NET, Second Edition44 Securing Web Services (continued) Web Service Enhancements – WSE 2.0 –Includes bug fixes and security tools to protect the Web Services and simplify deployment of secure Web services. Protect the page with NTFS and Windows authentication

45 Introduction to ASP.NET, Second Edition45 Summary Web Services expose part or all of an application Web Service ends in.asmx is used to identify the methods exposed WSDL schema is used to create a WSDL document that describes the functionality of the Web Service UDDI is used to locate Web Services Web Services may be called by the HTTPGet, HTTPPost, or by SOAP

46 Introduction to ASP.NET, Second Edition46 Summary (continued) WSDL creates a proxy class to invoke the Web Service The SOAP contract is an XML formatted document called the WSDL The Test page uses the HTTPGet method to test the Web Service Secure Web Services with traditional methods such as IIS Web Security, HTTPS with SSL, Windows authentication, and Passport authentication


Download ppt "Introduction to ASP.NET, Second Edition2 Chapter Objectives."

Similar presentations


Ads by Google