Chapter 7: Creating and Consuming XML Web Services Understanding XML Web Services Creating XML Web...
-
Upload
jeffery-butler -
Category
Documents
-
view
225 -
download
0
Transcript of Chapter 7: Creating and Consuming XML Web Services Understanding XML Web Services Creating XML Web...
Chapter 7: Creating and Consuming XML
Web Services Understanding XML Web Services
Creating XML Web Services
Deploying and Discovering XML Web Services
Consuming an XML Web Service
©Slide 2
Understanding XML Web Services
Overview of XML Web Services XML Web Services Infrastructure Communication Between the Client and the XML Web Service
©Slide 3
Overview of XML Web Services
XML Web service is a component . Using standard protocols, such as HTTP, XML, and SOAP, to
access the functionality . XML Web services use XML-based messaging to send and
receive data . Aplication independent with platforms.
©Slide 4
XML Web Services Infrastructure
XML Web services directories XML Web services discovery XML Web services description XML Web service wire formats
©Slide 5
Communication Between the Client and the XML Web Service
©Slide 6
Creating XML Web Services
Creating an XML Web Service
©Slide 7
Creating an XML Web Service
<%@ WebService Language=“Language" Class=“ClassName" %>
Imports System
Imports System.Web.Services
Public Class ClassName
Inherits WebService
<WebMethod()> Public Function FunctionName() As Type
Coding here
End Function
End Class
©Slide 8
Creating an XML Web Service(Cont)
You can write code direct into file XML Webservice or Codebehind
Code direct:
<%@ WebService Language=“Language" Class=“ClassServiceName" %>
Code behind
<%@ WebService Language=“Language" Codebehind=“WebServiceName.asmx.vb" Class=“ProjectName.ClassWebServiceName" %>
Note: Codebehind that mean coding are written into file *.asmx.vb
©Slide 9
Creating an XML Web Service(Cont)
You must change:
<System.Web.Services.WebService(Namespace:=
"http://tempuri.org/ProjectName/ClassServiceName")> _
Public Class ClassServiceName
Inherits System.Web.Services.WebService Open file *.asmx -> Change Codebehind and Class properties
<%@ WebService Language=“Language" Codebehind=“WebServiceName.asmx.vb" Class=“ProjectName.ClassWebServiceName" %>
Extension file of XML Webservice is *.asmx
©Slide 10
Example 1
This case code are written into *.asmx fileimports Systemimports System.Web.ServicesPublic Class ClassWebServiceA inherits
System.Web.Services.WebService<WebMethod()> Public Function GetSubject() As String()
Dim ArrSubject(2) as StringArrSubject(0)="Design Web Page"ArrSubject(1)="XML Webservices"ArrSubject(2)="ASP.NET Developer"return ArrSubject
End FunctionEnd Class
©Slide 11
Example 2
This case code are written into *.asmx.vb fileimports Systemimports System.Web.Services<System.Web.Services.WebService(Namespace:="http://tempuri.org/PWebService/ ClassWebServiceB ")>
Public Class ClassWebServiceB inherits System.Web.Services.WebService
<WebMethod()> Public Function GetSubject() As String()Dim ArrSubject(2) as StringArrSubject(0)="Design Web Page"ArrSubject(1)="XML Webservices"ArrSubject(2)="ASP.NET Developer"return ArrSubject
End FunctionEnd Class
©Slide 12
Deploying and Discovering XML Web Services
Publishing an XML Web Service Items Published with a Web Service Understanding the XML Web Services Discovery Mechanism . Configuring Discovery Information for a Web Service
©Slide 13
Publishing an XML Web Service
We have two way deploy XML Webservice: Setup Web XML WebService Create by manual which is the same Website (Create Virtual
Directory)
©Slide 14
Items Published with a Web Service
The Web application directory. The <WebService>.asmx file The <WebService>.disco file The Web.config file The \Bin directory
©Slide 15
Understanding the XML Web Services Discovery Mechanism
The XML Web service discovery mechanism enables a client application to locate or discover the documents that describe an XML Web service. The XML Web service discovery mechanism returns a service description document to a client. The service description document is written in Web Services Description Language (WSDL) and contains information about the capabilities of an XML Web service, its location, and how to interact with it
©Slide 16
Consuming an XML Web Service
Consuming an XML Web Service Adding a Web Reference Generating a Proxy Class Creating an Object of the Proxy Class Accessing the Web Service Using a Proxy Object Consuming the Methods Exposed by a Web Service
©Slide 17
Consuming an XML Web Service
Add a Web reference to the XML Web service in the client application by discovering the XML Web service that you want to consume.
Generate a proxy class for the XML Web service. Create an object of the XML Web service proxy class in the
client application. Access the XML Web service by using a proxy object.
©Slide 18
Add a Web reference to the XML Web service in the client application
©Slide 19
WebServices on the Local Machine
©Slide 20
A method of XML WebService
©Slide 21
Generating a Proxy Class
Proxy Class is created when you press to Add reference button.
The proxy class of an XML Web service contains instructions for calling each XML Web service method .
Visual Studio .NET uses WSDL to create the proxy class . The proxy class is described in the .wsdl file.
©Slide 22
Creating an Object of the Proxy Class
You need to include the proxy class namespace in your client application before you can create an object of the proxy class.
You create an object of the proxy class by using the new operator
Dim objWS as new ServerName.ClassNameService
Access to Method of XML Webservice
objWS.MethodName()