220 likes | 346 Views
Module 13: Consuming and Creating XML Web Services. Overview. Overview of Using XML Web Services Calling an XML Web Service Using HTTP Using a Proxy to Call an XML Web Service Creating an XML Web Service. Lesson: Overview of Using XML Web Services. What is an XML Web Service?
E N D
Overview • Overview of Using XML Web Services • Calling an XML Web Service Using HTTP • Using a Proxy to Call an XML Web Service • Creating an XML Web Service
Lesson: Overview of Using XML Web Services • What is an XML Web Service? • Why use XML Web Services? • Finding an XML Web Service • Multimedia: XML Web Service Execution Model
What is an XML Web Service? • Programmable logic accessible by standard Web protocols • Allows applications to send and receive information across the Internet • Language, protocol, and platform independent • Stateless architecture • Can be asynchronous • Based on an evolving W3C standard
Why Use XML Web Services? Northwind Traders Travel Site WeatherXML Web Service Pick your destination: Redmond The weatherForecast calls for: Rain Exchange Rate XML Web Service Internet The exchange rate is: $1.56 We can fly you there for only: $1,999.98 Airfare XML Web Service Airfare Database
Finding an XML Web Service Publish XML Web service URL and description 1 UDDI 2 Discover XML Web service 3 Locate XML Web service URL 4 Read .wsdl description Bind XML Web Service to Proxy 5 2 1 Call XML Web Service from the Web Form by Proxy 6 .disco WebForm 3 .wsdl 4 5 6 Web Service Proxy
Lesson: Calling an XML Web Service Using HTTP • How to Call an XML Web Service Using HTTP • Practice: Calling an XML Web Service Using HTTP
How to Call an XML Web Service Using HTTP • Navigate to the XML Web service URL • Select an XMLWeb servicemethod • Call the XML Web service method • View the XMLresponse 1 2 3 4
Practice: Calling an XML Web Service Using HTTP The Student will: • Enter an XML Web Service URL on the instructor machine • Select the XML Web service method to call • Enter values for parameters • View the returned XML Time: 5 Minutes
Lesson: Using a Proxy to Call an XML Web Service • Using Proxies to Call XML Web Services • How to Use a Proxy to Call an XML Web Service • Instructor-Led Practice: Using a Proxy to Call an XML Web Service • XML Web Service Error Handling • Demonstration: Testing the Availability of an XML Web Service
Using Proxies to Call XML Web Services • Appear the same as the original class, but do not contain application logic • Use SOAP to interact with the XML Web Service • Created from the ServiceName.asmx.wsdl file • Add members to manage interactions with the XML Web service and support asynchronous calls WebForm Internet XML WebService SOAP Proxy
How to Use a Proxy to Call an XML Web Service • Create a Web reference for the XML Web Service • Create an instance of the XML Web Service • Call the Web methods of the XML Web Service • Build the ASP.NET Web Application 1 2 3 4 Sub Button1_Click(s As Object, e As EventArgs)... Dim ProxyGetStocks As New _ GetStocks.localhost.Service1() lblResults.Text = _ ProxyGetStocks.GetRating("Contoso") End Sub C# Code Example
Instructor-Led Practice: Using a Proxy to Call an XML Web Service • Create a new ASP.NET Web Application project • Create a proxy for an XML Web service • Test with a browser • View the reference.vb or reference.cs file
XML Web Service Error Handling • Service unavailable • SOAP exceptions from XML Web Services GetStocks.StockWebRef.Service1 ProxyGetStocks = new GetStocks.StockWebRef.Service1(); ProxyGetStocks.Timeout = 10000; try { lblMessage.Text = ProxyGetStocks.GetRating(TextBox1.Text); } catch (Exception err) { lblMessage.Text = err.Message; } Visual Basic .NET Code Example
Demonstration: Testing the Availability of a XML Web Service • Set a timeout error handling Try…Catch statement • Slow the Web service • Test the exception
Lesson: Creating an XML Web Service • How to Create an XML Web Service • XML Web Service Code • Instructor-Led Practice: Creating an XML Web Service
How to Create an XML Web Service 1 • Create a new XML Web Service project in Visual Studio .NET • Declare the WebMethod functions • Build the XML Web Service project • Test witha browser 2 3 4
XML Web Service Code • .asmx page • .asmx.vb page <%@ WebService Language="vb" Codebehind="Service1.asmx.vb" Class="XMLWebServiceName.Service1" %> Imports System Imports System.Web.Services Class Service1 <WebMethod()> Public Function function1() As type 'function_here End Function End Class C# Code Example
Instructor-Led Practice: Creating an XML Web Service • Create an XML Web Service • Test the XML Web Service • Change the Namespace
Review • Overview of Using XML Web Services • Calling an XML Web Service Using HTTP • Using a Proxy to Call an XML Web Service • Creating an XML Web Service
Lab 13: Consuming and Creating XML Web Services Logon Page Login.aspx BenefitsHome PageDefault.aspx CohoWinery Page HeaderHeader.ascx ASPState Menu ComponentClass1.vb or Class1.cs Registration Register.aspx Web.config tempdb Life InsuranceLife.aspx RetirementRetirement.aspx MedicalMedical.aspx DentalDental.aspx XML Web ServicedentalService1.asmx ProspectusProspectus.aspx DoctorsDoctors.aspx User Controlnamedate.ascx Lab Web Application XML Files Doctors Dentists