Presentation is loading. Please wait.

Presentation is loading. Please wait.

XML Web Service. Overview of XML Web Service ASP.NET XML Web services enable you to remotely access the properties and methods of classes across a network.

Similar presentations


Presentation on theme: "XML Web Service. Overview of XML Web Service ASP.NET XML Web services enable you to remotely access the properties and methods of classes across a network."— Presentation transcript:

1 XML Web Service

2 Overview of XML Web Service ASP.NET XML Web services enable you to remotely access the properties and methods of classes across a network Web services are built on open standards – such as HTTP, XML, and SOAP

3 Creating a Simple XML Web Service Imports System Imports System.Web.Services Public Class TemperatureService : Inherits WebService Public Function ToCelsius( TF As Double ) As Double Return ( 5/9 ) * ( TF - 32 ) End Function Public Function ToFahrenheit( TC As Double ) As Double Return ( 9/5 ) * Tc + 32 End Function End Class TemperatureService.asmx

4 WebService & WebMethod Attributes Public Function toCelsius(TF As Double) As Double … End Function <WebService(Description:=“Temperature Service”, NameSpace:= “http://127.0.0.1/Hello”)> Public Class TemperatureService … End Class

5 Invoking an XML Web Service with HTTP-Get Convert Example:

6 Invoking an XML Web Service with HTTP-Post <form method="post" action="/Services/TemperatureService.asmx/ToCelsius"> Example:

7 To create a Web Service project 1.On the File menu, point to New, and then click Project. 2.In the New Project dialog box, select either the Visual Basic Projects or the Visual C# Projects folder. 3.Click the ASP.NET Web Service icon. 4.Change the name of the project to what you want it to be. 5.If you are not developing the Web Service on your localhost Web server, enter the address of the Web server on which you will develop the Web Service. 6.Click OK to create the project. Create a Web Service Project

8 When using Visual Studio.NET to create Web Services in managed code, you use a standard deployment model: you compile your project and then you deploy the resulting files to a production server. The project DLL file contains the Web Services code-behind class file (.asmx.vb or.asmx.cs) along with all other class files included in your project, but not the.asmx file itself. You then deploy this single project.dll file to the production server without any source code. When the Web Service receives a request, the project.dll file is loaded and executed. Create a Web Service Project

9 Accessing an XML Web Service Through a Proxy Class Step 1: Use the Wsdl.exe tool to generate the source code file for the proxy class Example: wsdl.exe /l:vb http://www.yoursite.com/services/test.asmx?wsdl test.vb

10 Accessing an XML Web Service Through a Proxy Class Step 2: Compile the source code file for the proxy class Example: vbc /t:library /r:System.dll,System.Web.Services.dll,System.Xml.dll text.vb test.dll

11 Accessing an XML Web Service Through a Proxy Class Step 3: Copy the compiled proxy class into the ASP.Net application’s /bin directory

12 Using an XML Web Service Proxy Class Sub Button_Click(s as Object, e as EventArgs) Dim objTemp As New TemperatureService lblTest.Text = objTemp.ToCelsius(txtTest.Text) End Sub …

13 To Add a Web Reference to a Project 1.In Solution Explorer, select a project that supports adding Web references. 2.On the Project menu, choose Add Web Reference. 3.In the Add Web Reference dialog box, type the URL for the Web Service in the Address text box, and then choose the Arrow Icon. 4.Verify that the items in the Available References box are the items you want to reference in your project, and then choose Add Reference. 5.In Solution Explorer, expand the Web References folder to note the namespace for the Web reference classes that are available to the items in your project.

14 When accessing Web Services in managed code, a proxy class and the.NET Framework handle all of the infrastructure coding. Accessing a Web Service follows these basic steps: Locate the Web Service you want to access. Create a proxy class for the Web Service by adding a Web reference to your project. Reference the proxy class in the client code by including its namespace. Create an instance of the Web Service proxy class in the client code. Access the Web Service using the methods of the proxy. Accessing Web Services in Managed Code

15 To simplify the coding model, applications written in managed code use a Web reference to locally represent each Web Service. You add a Web reference to your project using the Add Web Reference dialog. This dialog box supports browsing Web addresses for a Web Service. Locating a Web Service and Adding a Web Reference

16 Reference the Proxy Class The generated proxy class has its own namespace associated with it, and you must add the namespace to your client application before you can create an instance of that class.

17 Create an Instance of the Proxy Class Before you can call any of the methods of the proxy class, you must first create an instance of that class. This process does not differ at all from creating an instance of any other class.

18 Access the Web Service Using the Proxy To access a Web Service method, your client application invokes either the corresponding synchronous method or asynchronous methods of the proxy object. These methods in turn do the necessary work to remote the call over the wire to call the desired Web Service method. By default, the proxy class uses SOAP to access the Web Service method, as SOAP supports the richest set of data types of the three supported protocols (HTTP-GET, HTTP-POST, and HTTP-SOAP).

19 To Add a New Web Service to an Existing Web Project 1.In Solution Explorer, select the project to which you want to add a Web Service. 2.On the Project menu, click Add Web Service. Alternatively, right-click the project name, point to Add and then click Add Web Service. 3.The Add New Item dialog appears. By default, the dialog box selects the ASP.NET Web Service template and supplies a name for the new Web Service in the Name box. 4.Click Open to add the Web Service to your project.

20 To Add an Existing Web Service to an Existing Web Project 1.In Solution Explorer, select the project to which you want to add an existing Web Service. 2.On the Project menu, select Add Existing Item. Alternatively, right-click the project name, point to Add and then click Add Existing Item. The Add Existing Item dialog box appears. 3.In the Files of type list, click Web Files. 4.Select the.asmx file for the Web Service you want to add. 5.Click Open to add the Web Service to your project.


Download ppt "XML Web Service. Overview of XML Web Service ASP.NET XML Web services enable you to remotely access the properties and methods of classes across a network."

Similar presentations


Ads by Google