meljun cortes vb.net understanding web service.net
TRANSCRIPT
![Page 1: MELJUN CORTES Vb.net understanding web service.net](https://reader038.vdocuments.net/reader038/viewer/2022110218/58806c541a28ab64028b4609/html5/thumbnails/1.jpg)
Visual Basic .NET Programming
What is a What is a What is a What is a Web Service?Web Service?Web Service?Web Service?
� allows access to components by means of
Internet and HTTP
� a class that is stored on one computer
that can be accessed on another computer
over the network
Understanding Web Service * Property of STIPage 1 of 14
� supporting frameworks for the Web
services:
� Open Internet Protocols
� XML Messages and SOAP
� Messages defined by Web Services
Description Language (WSDL)
![Page 2: MELJUN CORTES Vb.net understanding web service.net](https://reader038.vdocuments.net/reader038/viewer/2022110218/58806c541a28ab64028b4609/html5/thumbnails/2.jpg)
Visual Basic .NET Programming
Web Service Web Service Web Service Web Service ModuleModuleModuleModule
� used to group the files needed to create a
Web service
� contains two files:
� .asmx
• includes the WebService directive
.asmx.vb file
Understanding Web Service * Property of STIPage 2 of 14
� .asmx.vb file
• contains the code that executes when a
Web Service method is invoked
<%@ WebService Language=”vb”
CodeBehind=”AdminUsr.asmx.vb”
Class=”WebApp.AdminUsr” %>
![Page 3: MELJUN CORTES Vb.net understanding web service.net](https://reader038.vdocuments.net/reader038/viewer/2022110218/58806c541a28ab64028b4609/html5/thumbnails/3.jpg)
Visual Basic .NET Programming
Adding Public Adding Public Adding Public Adding Public Subroutines or FunctionsSubroutines or FunctionsSubroutines or FunctionsSubroutines or Functions
� Example:
<WebMethod()> Public Function
AddAdminUsr(ByVal strName As
String) As String
‘ Functionality to add a user and
return new ID
Understanding Web Service * Property of STIPage 3 of 14
return new ID
…
Return strNewId
End Function
<WebMethod()> Public Sub
DeleteAdminUsr(ByVal strId As
String)
‘ Functionality to delete a user based
on ID
…
End Sub
![Page 4: MELJUN CORTES Vb.net understanding web service.net](https://reader038.vdocuments.net/reader038/viewer/2022110218/58806c541a28ab64028b4609/html5/thumbnails/4.jpg)
Visual Basic .NET Programming
Dynamic Dynamic Dynamic Dynamic Discovery DocumentDiscovery DocumentDiscovery DocumentDiscovery Document
� contains information about the Web
service
� used to locate and discover Web services
� automatically created by ASP.NET
Understanding Web Service * Property of STIPage 4 of 14
� automatically created by ASP.NET
� return the details of all Web Services
� uses the .vsdisco file extension
� used to exclude particular folders from
the dynamic discovery process
![Page 5: MELJUN CORTES Vb.net understanding web service.net](https://reader038.vdocuments.net/reader038/viewer/2022110218/58806c541a28ab64028b4609/html5/thumbnails/5.jpg)
Visual Basic .NET Programming
HTML Description Page HTML Description Page HTML Description Page HTML Description Page and WSDL Documentand WSDL Documentand WSDL Documentand WSDL Document
� The HTML description page
� describes Web services methods and
arguments
� displayed when Web service URL is entered
without specifying a particular method
name
� contains simple test utility methods
� provides test facilities for each methods of
Understanding Web Service * Property of STIPage 5 of 14
� provides test facilities for each methods of
the Web service
� allows you to provide parameter through
an input field
� follows the format:
http://webservername:port/webservi
ce.asmx.
� Example:
http://localhost:3163/MyService.as
mx
![Page 6: MELJUN CORTES Vb.net understanding web service.net](https://reader038.vdocuments.net/reader038/viewer/2022110218/58806c541a28ab64028b4609/html5/thumbnails/6.jpg)
Visual Basic .NET Programming
HTML Description Page HTML Description Page HTML Description Page HTML Description Page and WSDL Documentand WSDL Documentand WSDL Documentand WSDL Document
� Web Services Description Language (WSDL)
� describes methods, arguments and
responses of a Web service
� created automatically by adding the ?WSDL
switch to the Web service URL
� Example:
Understanding Web Service * Property of STIPage 6 of 14
� Example:
http://localhost:3163/MyService.as
mx?WSDL
![Page 7: MELJUN CORTES Vb.net understanding web service.net](https://reader038.vdocuments.net/reader038/viewer/2022110218/58806c541a28ab64028b4609/html5/thumbnails/7.jpg)
Visual Basic .NET Programming
Invoking a Web Service Invoking a Web Service Invoking a Web Service Invoking a Web Service from a Browser from a Browser from a Browser from a Browser
and a Clientand a Clientand a Clientand a Client
� To invoke a Web Service from a browser:
� enter the URL of the service, specify the
method name to run as well as parameter
values
� Syntax:
http://webservername/vdir/webservi
Understanding Web Service * Property of STIPage 7 of 14
http://webservername/vdir/webservi
cename.asmx/MethodName?parameter
=value
� Examples:
http://www.myserver.com/User/Admin
Usr.asmx/AddAdminUsr?strName=Man
ny
<?xml version=”1.0” ?>
<string
xmlns=http://tempuri.org/>43-
124-21</string>
![Page 8: MELJUN CORTES Vb.net understanding web service.net](https://reader038.vdocuments.net/reader038/viewer/2022110218/58806c541a28ab64028b4609/html5/thumbnails/8.jpg)
Visual Basic .NET Programming
Invoking a Web Service Invoking a Web Service Invoking a Web Service Invoking a Web Service from a Browser from a Browser from a Browser from a Browser
and a Clientand a Clientand a Clientand a Client
� HTTP GET method
� used to send the form data to the Web
server
� most commonly used for testing purposes
� SOAP protocol
� used for real application-to-application
Understanding Web Service * Property of STIPage 8 of 14
� used for real application-to-application
communication
� difference between the HTTP-GET and
SOAP
� the way of sending data to the Web server
![Page 9: MELJUN CORTES Vb.net understanding web service.net](https://reader038.vdocuments.net/reader038/viewer/2022110218/58806c541a28ab64028b4609/html5/thumbnails/9.jpg)
Visual Basic .NET Programming
Invoking a Web Service Invoking a Web Service Invoking a Web Service Invoking a Web Service from a Browser from a Browser from a Browser from a Browser
and a Clientand a Clientand a Clientand a Client
� To invoke a Web service from a client:
� add a Web reference to the Web Service
� enter the URL for the .asmx file
� select the required references
� create the client code for accessing a
component
Understanding Web Service * Property of STIPage 9 of 14
� Example:
Private Sub btnSubmit_Click(ByVal
sender As System.Object, _
ByVal e As System.EventArgs)
Handles btnSubmit.Click
’Services is the given namespace
Dim usr As New Services.user( )
MessageBox.Show(usr.AddUser(txtNam
e.Text))
End Sub
![Page 10: MELJUN CORTES Vb.net understanding web service.net](https://reader038.vdocuments.net/reader038/viewer/2022110218/58806c541a28ab64028b4609/html5/thumbnails/10.jpg)
Visual Basic .NET Programming
Demo: Creating a Demo: Creating a Demo: Creating a Demo: Creating a Web ServiceWeb ServiceWeb ServiceWeb Service
� open Visual Studio 2005
� File > New Web Site
� select ASP.NET Web Service
� set Location to File System
� set Language to Visual Basic then click
OK
� delete the asmx file
Understanding Web Service * Property of STIPage 10 of 14
� delete the asmx file
� delete the vb file
� right-click on the project name and click
Add New Item
� select Web Service in the Templates list
then set the Web service and click Add
� right-click on the App_Code and click
Add New Item
� select Class from the Installed Templates
list
� set the class name then click Add
![Page 11: MELJUN CORTES Vb.net understanding web service.net](https://reader038.vdocuments.net/reader038/viewer/2022110218/58806c541a28ab64028b4609/html5/thumbnails/11.jpg)
Visual Basic .NET Programming
Demo: Creating a Demo: Creating a Demo: Creating a Demo: Creating a Web ServiceWeb ServiceWeb ServiceWeb Service
� open the Code Editor for the .asmx file,
locate the Public Class definition then
modify the WebService attribute
<WebService(Namespace:=”http://tem
puri.org/”, _
Description:=” Web service demo
information.”
Understanding Web Service * Property of STIPage 11 of 14
information.”
)> Public Class WebServiceDemo
� delete the code:
<WebMethod()> _
Public Function HelloWorld()
As String
Return "Hello World"
End Function
![Page 12: MELJUN CORTES Vb.net understanding web service.net](https://reader038.vdocuments.net/reader038/viewer/2022110218/58806c541a28ab64028b4609/html5/thumbnails/12.jpg)
Visual Basic .NET Programming
Demo: Creating a Demo: Creating a Demo: Creating a Demo: Creating a Web ServiceWeb ServiceWeb ServiceWeb Service
� To define the Web Service methods:
� add WebMethod attribute and Web service
method
<WebMethod(Description:="Retrieves
welcome message.")> _
Public Function GetMessage()
As String
Understanding Web Service * Property of STIPage 12 of 14
As String
GetMessage = "Learning Web
services is fun!"
End Function
� To test the Web Service:
� right-click on the project name and select
Build Web Site
� right-click the .asmx file, and then click
View in Browser
![Page 13: MELJUN CORTES Vb.net understanding web service.net](https://reader038.vdocuments.net/reader038/viewer/2022110218/58806c541a28ab64028b4609/html5/thumbnails/13.jpg)
Visual Basic .NET Programming
Demo: Creating a Demo: Creating a Demo: Creating a Demo: Creating a Web ServiceWeb ServiceWeb ServiceWeb Service
Understanding Web Service * Property of STIPage 13 of 14
� click the Service Description hyperlink
![Page 14: MELJUN CORTES Vb.net understanding web service.net](https://reader038.vdocuments.net/reader038/viewer/2022110218/58806c541a28ab64028b4609/html5/thumbnails/14.jpg)
Visual Basic .NET Programming
Demo: Creating a Demo: Creating a Demo: Creating a Demo: Creating a Web ServiceWeb ServiceWeb ServiceWeb Service
� click the Back button
� click the hyperlink of the method of the
Web Service
Understanding Web Service * Property of STIPage 14 of 14
� click the Invoke button