1 / 36

XML Web Services

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 can interact with it. The code itself is not exposed, the interface is Accessible through standard Web protocols

valin
Download Presentation

XML Web Services

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

  5. 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

  6. Building and Consuming a Web Service

  7. 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 • 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

  8. 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

  9. Creating a Web Service (Page 1) • To create the WebService document: • Select Project from the menu bar • Select WebService… from the Project menu • Verify that "WebService" is the selected Template, give it a name (i.e. "ServiceTSCategories") and click the <Open> 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

  10. 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.

  11. Creating a Web Service (Page 3) • Example: <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

  12. Creating a Web Service (Page 4) • In Visual Studio .NET compiling the Web Service generates the WSDL document, DISCO document and test Web page

  13. 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)

  14. 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

  15. 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

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

  17. The Web Method

  18. Previewing the Web Service Home Page (Page 1) • 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 the <Invoke> button to test GetCatMethod() • XML document returned (XML data within a DataSet element) • Top section describes data; bottom section contains data

  19. Previewing the Web Service Home Page (Page 2) • Go <Back>, 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

  20. Creating a Web Service

  21. Creating a Web Service

  22. Creating a Web Service

  23. Creating a Web Service

  24. Create a New Web Method

  25. 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

  26. 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

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

  28. Consuming a Web Service from an ASP.NET Page

  29. Consuming a Web Service from an ASP.NET Page

  30. Consuming a Web Service from an ASP.NET Page

  31. Consuming a Web Service from an ASP.NET Page

  32. Consuming a Web Service from an ASP.NET Page (Page 2) • 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()

  33. Consuming a Web Service from an ASP.NET Page

  34. Consuming a Web Service from an ASP.NET Page • Create a new WebForm—WebForm2.aspx • Add a DataGrid— • ID--dgCategories

  35. Consuming a Web Service from an ASP.NET Page

  36. 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

More Related