Module 13 Consuming and Creating XML Web Services

Module 13: Consuming and Creating XML Web Services

Overview n Overview of Using XML Web Services n Calling an XML Web Service Using HTTP n Using a Proxy to Call an XML Web Service n Creating an XML Web Service

Lesson: Overview of Using XML Web Services n What is an XML Web Service? n Why use XML Web Services? n Finding an XML Web Service n Multimedia: XML Web Service Execution Model

What is an XML Web Service? n n Programmable logic accessible by standard Web protocols l Allows applications to send and receive information across the Internet l Language, protocol, and platform independent l Stateless architecture l Can be asynchronous Based on an evolving W 3 C standard

Why Use XML Web Services? Northwind Traders Travel Site Weather XML Web Service Pick your destination: Redmond The weather Forecast calls for: Rain Internet The exchange rate is: $1. 56 We can fly you there for only: $1, 999. 98 Airfare XML Web Service Exchange Rate XML Web Service Airfare Database

Finding an XML Web Service 1 2 3 4 5 6 Publish XML Web service URL and description Discover XML Web service Locate XML Web service URL Read. wsdl description Bind XML Web Service to Proxy Call XML Web Service from the Web Form by Proxy Web Form 5 Proxy UDDI 2 1 3 . disco 4 . wsdl 6 Web Service

Multimedia: XML Web Service Execution Model

Lesson: Calling an XML Web Service Using HTTP n How to Call an XML Web Service Using HTTP n Practice: Calling an XML Web Service Using HTTP

How to Call an XML Web Service Using HTTP 1. 1 Navigate to the XML Web service URL 2 Select an XML 2. Web service method 3 Call the XML Web 3. service method 4 View the XML 4. response

Practice: Calling an XML Web Service Using HTTP The Student will: n Enter an XML Web Service URL on the instructor machine n Select the XML Web service method to call n Enter values for parameters n View the returned XML Time: 5 Minutes

Lesson: Using a Proxy to Call an XML Web Service n Using Proxies to Call XML Web Services n How to Use a Proxy to Call an XML Web Service n Instructor-Led Practice: Using a Proxy to Call an XML Web Service Error Handling n Demonstration: Testing the Availability of an XML Web Service

Using Proxies to Call XML Web Services n Appear the same as the original class, but do not contain application logic n Use SOAP to interact with the XML Web Service n Created from the Service. Name. asmx. wsdl file n Add members to manage interactions with the XML Web service and support asynchronous calls Web Form Proxy Internet SOAP XML Web Service

How to Use a Proxy to Call an XML Web Service 1. 1 Create a Web reference for the XML Web Service 2 Create an instance of the XML Web Service 2. 3 Call the Web methods of the XML Web Service 3. 4 Build the ASP. NET Web Application 4. Sub Button 1_Click(s As Object, e As Event. Args). . . Dim Proxy. Get. Stocks As New _ Get. Stocks. localhost. Service 1() lbl. Results. Text = _ Proxy. Get. Stocks. Get. Rating("Contoso") End Sub C# Code Example

Instructor-Led Practice: Using a Proxy to Call an XML Web Service n Create a new ASP. NET Web Application project n Create a proxy for an XML Web service n Test with a browser n View the reference. vb or reference. cs file

XML Web Service Error Handling n Service unavailable Get. Stocks. Stock. Web. Ref. Service 1 Proxy. Get. Stocks = new Get. Stocks. Stock. Web. Ref. Service 1(); Proxy. Get. Stocks. Timeout = 10000; try { lbl. Message. Text = Proxy. Get. Stocks. Get. Rating(Text. Box 1. Text); } catch (Exception err) { lbl. Message. Text = err. Message; } n SOAP exceptions from XML Web Services Visual Basic. NET Code Example

Demonstration: Testing the Availability of a XML Web Service n Set a timeout error handling Try…Catch statement n Slow the Web service n Test the exception

Lesson: Creating an XML Web Service n How to Create an XML Web Service Code n Instructor-Led Practice: Creating an XML Web Service

How to Create an XML Web Service 1. 1 Create a new XML Web Service project in Visual Studio. NET 2 Declare the Web. Method functions 2. 3 Build the XML Web Service project 3. 4 Test with 4. a browser

XML Web Service Code n . asmx page <%@ Web. Service Language="vb" Codebehind="Service 1. asmx. vb" Class="XMLWeb. Service. Name. Service 1" %> n . asmx. vb page Imports System. Web. Services Class Service 1 <Web. Method()> Public Function function 1() As type 'function_here End Function End Class C# Code Example

Instructor-Led Practice: Creating an XML Web Service n Create an XML Web Service n Test the XML Web Service n Change the Namespace

Review n Overview of Using XML Web Services n Calling an XML Web Service Using HTTP n Using a Proxy to Call an XML Web Service n Creating an XML Web Service

Lab 13: Consuming and Creating XML Web Services Logon Page Login. aspx Benefits Home Page Coho Winery Default. aspx Page Header Menu Component Registration Register. aspx Header. ascx Web. config Class 1. vb or Class 1. cs Life Insurance Retirement Medical Dental Life. aspx Retirement. aspx Medical. aspx Dental. aspx Lab Web Application Prospectus Doctors User Control Prospectus. aspx Doctors. aspx namedate. ascx ASPState tempdb XML Web Service dental. Service 1. asmx XML Files Doctors Dentists
- Slides: 22