1 / 46

Chapter Objectives

Chapter Objectives. 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

axl
Download Presentation

Chapter Objectives

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Chapter Objectives Introduction to ASP.NET, Second Edition

  2. 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 Introduction to ASP.NET, Second Edition

  3. 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 Introduction to ASP.NET, Second Edition

  4. 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 Introduction to ASP.NET, Second Edition

  5. 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 Introduction to ASP.NET, Second Edition

  6. 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) Introduction to ASP.NET, Second Edition

  7. Overview of Web Services (continued) Introduction to ASP.NET, Second Edition

  8. 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 Introduction to ASP.NET, Second Edition

  9. 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 Introduction to ASP.NET, Second Edition

  10. Building and Consuming a Web Service Introduction to ASP.NET, Second Edition

  11. 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 Introduction to ASP.NET, Second Edition

  12. 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) Introduction to ASP.NET, Second Edition

  13. 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 Introduction to ASP.NET, Second Edition

  14. Locating Web Services (continued) Introduction to ASP.NET, Second Edition

  15. 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 Introduction to ASP.NET, Second Edition

  16. 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 Introduction to ASP.NET, Second Edition

  17. 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 Introduction to ASP.NET, Second Edition

  18. 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 Introduction to ASP.NET, Second Edition

  19. 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 Introduction to ASP.NET, Second Edition

  20. 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. Introduction to ASP.NET, Second Edition

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

  22. 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 Introduction to ASP.NET, Second Edition

  23. 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 Introduction to ASP.NET, Second Edition

  24. 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 Introduction to ASP.NET, Second Edition

  25. Creating a Web Service (continued) Introduction to ASP.NET, Second Edition

  26. Previewing the Web Service Home Page • View the Web Service home page in a browser • http://localhost/Ch11WebService/Ch11WS_ProductsDS.asmx • Click the hyperlink GetCatMethod() takes you to URL: • http://localhost/Chapter11WebService/Ch11WS_ProductsDS.asmx?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?WSDL Introduction to ASP.NET, Second Edition

  27. Creating a Web Service (continued) Introduction to ASP.NET, Second Edition

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

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

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

  31. 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 Introduction to ASP.NET, Second Edition

  32. 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 Introduction to ASP.NET, Second Edition

  33. 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_ProductsDS.asmx Introduction to ASP.NET, Second Edition

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

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

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

  37. 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() Introduction to ASP.NET, Second Edition

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

  39. Locating Web Services • UDDI - directory service for registering and searching for Web Services • Third-party Web Services • www.xmethods.net • www.coldrooster.com • www.asp.net • www.gotdotnet.com • Local Web Services • Discovery document points to Web Services Introduction to ASP.NET, Second Edition

  40. Locating Web Services (continued) Introduction to ASP.NET, Second Edition

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

  42. 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 Introduction to ASP.NET, Second Edition

  43. 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 <authentication mode= "Windows"> </authentication> Introduction to ASP.NET, Second Edition

  44. Summary • Web Services expose part or all of an application • Web Service ends in .asmx • <WebMethod> 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 Introduction to ASP.NET, Second Edition

  45. 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 Introduction to ASP.NET, Second Edition

More Related