Presentation is loading. Please wait.

Presentation is loading. Please wait.

XML Web Services ASP.NET. Overview of Web Services (Page 1) Web Service – Part or all of a Web application that is publicly exposed so that other applications.

Similar presentations


Presentation on theme: "XML Web Services ASP.NET. Overview of Web Services (Page 1) Web Service – Part or all of a Web application that is publicly exposed so that other applications."— Presentation transcript:

1 XML Web Services ASP.NET

2 Overview of Web Services (Page 1) 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 Remote Procedure Call (RPC) – Used to call another application on the Web server

3 Overview of Web Services (Page 2) 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 Web Service is communicating with any back-end applications or data sources

4 Overview of Web Services (Page 3) 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

5 Overview of Web Services (Page 4) 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

6 Overview of Web Services (Page 5) 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)

7 Overview of Web Services

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

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 A sample "Business-to-Business" Web Service – Tara Store Creates a Web Service which provides product data – MaryKate’s Housewares Integrates product data into its own Web site

10 Building and Consuming a Web Service

11 Building a Web Service Web Service file extentions –.asmx and.asmx.vb for the code behind the page Import System.Web.Services namespace Three major components 1. Web Service on the server 2. Web Service client application that calls the Web Service via a Web reference 3. A WSDL Web Service description document that describes the functionality of the Web Service

12 Locating Web Services (Page 1) 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)

13 Locating Web Services (Page 2) 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

14 Locating Web Services (continued)

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

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 (Simple Object Access Protocol) is default method by which ASP.NET internally calls a Web Service

17 The SOAP Contract (Page 1) 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

18 The SOAP Contract (Page 2) 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

19 The SOAP Contract (Page 3) 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

20 Creating a Web Service (Page 1) To create the WebService document: 1. Select Project from the menu bar 2. Select WebService… from the Project menu 3. Verify that "WebService" is the selected Template, give it a name (i.e. "ServiceTSCategories") and click the button Keyword WebService comes before class header – Statement is part of the class header – Must be qualified if the System.Web.Services namespace is not imported

21 Creating a Web Service (Page 2) Properties for the keyword WebService: – Namespace property Unique URL which distinguishes your Web Service from others (default domain is "tempuri.org") Replace with your organization’s domain name – Description property Used to provide information about your Web Service Can include HTML commands – Name property Name displayed in the Web Service home page.

22 Creating a Web Service (Page 3) Example: <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 Creating a Web Service (Page 4) In Visual Studio.NET compiling the Web Service generates the WSDL document, DISCO document and test Web page

24 The Web Method (Page 1) Create new function in "Code Behind the Page" – Exposes the method to applications in which the WebService is instantiated Keyword WebMethod comes before class header – Statement is part of the function header – Must be qualified if the System.Web.Services namespace is not imported (like WebService)

25 The Web Method (Page 2) Properties in statement prior to method header: – BufferResponse property Store the response on the server until the entire function is processed If set to True, improves server performance by minimizing communication – CacheDuration property Number of seconds to cache Web service results Automatically cache the results for each unique parameter

26 The Web Method (Page 3) Properties before method header (con): – MessageName property Name for the method displayed in the Web page Uses the name of the function or method if this property is not included – Description property Can format the description with HTML

27 The Web Method (Page 4) Example: <WebMethod(CacheDuration:=10, _ Description:="HelloWorld() says hello.")> _ Public Function HelloWorld() As String Return "Hello World" End Function

28 The Web Method

29 Previewing the Web Service Home Page (Page 1) View the Web Service home page in a browser – http://localhost/Ch11WebService/Ch11WS_ProductsDS.asmx http://localhost/Ch11WebService/Ch11WS_ProductsDS.asmx Click the hyperlink GetCatMethod() takes you to URL: – http://localhost/Chapter11WebService/Ch11WS_ProductsDS. asmx?op=GetCat () +Method http://localhost/Chapter11WebService/Ch11WS_ProductsDS. asmx?op=GetCat () +Method Click the button to test GetCatMethod () – XML document returned (XML data within a DataSet element) – Top section describes data; bottom section contains data

30 Previewing the Web Service Home Page (Page 2) Go, enter hyperlink for Service Description – View the service contract – Service Description URL – "?WSDL" is appended to Web Service URL – http://localhost/Ch11WebService/Service1.asmx?WSDL http://localhost/Ch11WebService/Service1.asmx?WSDL

31 Creating a Web Service

32

33

34

35 Create a New Web Method

36 Using a Web Service (Page 1) Call Web Services via protocol: – HTTP Get or HTTP Post Limit to primitive data types (integers, strings, arrays of primitive data types) – SOAP (Simple Object Access Protocol) Send any structure, class or enumerator, i.e. a DataSet

37 Using a Web Service (Page 2) 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

38 Consuming a Web Service from an ASP.NET Page (Page 1) In Web Form application, add a Web Reference in Solution Explorer 1. Select Project from the menu bar 2. Select Add Web Reference… from the Project menu (or right-click "Web References" in Solution Explorer) 3. Find or enter the Web Service URL, i.e. http://localhost/Chapter11WebService/Ch11WS_ProductsDS. asmxhttp://localhost/Chapter11WebService/Ch11WS_ProductsDS. asmx 4. Give the reference a Web reference name: 5. Click the button

39 Consuming a Web Service from an ASP.NET Page

40

41

42

43 Create an object from the Web Service reference Call a WebMethod of the Web Service Example: Dim dsProducts As New DataSet Dim objWebService As localhost.Chapter11WebService = New localhost.Chapter11WebService dsProducts = objWebService.WS_GetProducts() dgProdList.DataSource = dsProducts.Tables(0) dgProdList.DataBind() Consuming a Web Service from an ASP.NET Page (Page 2)

44 Consuming a Web Service from an ASP.NET Page

45 Create a new WebForm—WebForm2.aspx Add a DataGrid— – ID--dgCategories

46 Consuming a Web Service from an ASP.NET Page

47 Locating Web Services UDDI - directory service for registering and searching for Web Services Third-party Web Services – www.xmethods.net www.xmethods.net – www.coldrooster.com www.coldrooster.com – www.asp.net www.asp.net – www.gotdotnet.com www.gotdotnet.com Local Web Services – Discovery document points to Web Services

48 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

49 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


Download ppt "XML Web Services ASP.NET. Overview of Web Services (Page 1) Web Service – Part or all of a Web application that is publicly exposed so that other applications."

Similar presentations


Ads by Google