meljun cortes vb.net_understanding web service.net
TRANSCRIPT
8/8/2019 MELJUN CORTES VB.net_Understanding Web Service.net
http://slidepdf.com/reader/full/meljun-cortes-vbnetunderstanding-web-servicenet 1/14
Visual Basic .NET Programming
What is aWhat is aWhat is aWhat 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 STI
Page 1 of 14
supporting frameworks for the Web
services: Open Internet Protocols
XML Messages and SOAP
Messages defined by Web Services
Description Language (WSDL)
8/8/2019 MELJUN CORTES VB.net_Understanding Web Service.net
http://slidepdf.com/reader/full/meljun-cortes-vbnetunderstanding-web-servicenet 2/14
Visual Basic .NET Programming
Web ServiceWeb ServiceWeb ServiceWeb Service
Module Module Module Module
used to group the files needed to create a
Web service
contains two files:
.asmx
• includes the WebService directive
Understanding Web Service * Property of STI
Page 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” %>
8/8/2019 MELJUN CORTES VB.net_Understanding Web Service.net
http://slidepdf.com/reader/full/meljun-cortes-vbnetunderstanding-web-servicenet 3/14
Visual Basic .NET Programming
Adding Public Adding Public Adding Public Adding Public
Subroutines or FunctionsSubroutines or FunctionsSubroutines or FunctionsSubroutines or Functions
Example:
<WebMethod()> Public FunctionAddAdminUsr(ByVal strName As
String) As String
‘ Functionality to add a user and
Understanding Web Service * Property of STI
Page 3 of 14
re urn new
…
Return strNewIdEnd Function
<WebMethod()> Public Sub
DeleteAdminUsr(ByVal strId As
String)
‘ Functionality to delete a user based
on ID
…
End Sub
8/8/2019 MELJUN CORTES VB.net_Understanding Web Service.net
http://slidepdf.com/reader/full/meljun-cortes-vbnetunderstanding-web-servicenet 4/14
Visual Basic .NET Programming
DynamicDynamicDynamicDynamic
Discovery Document Discovery Document Discovery Document Discovery Document
contains information about the Web
service
used to locate and discover Web services
automaticall created b ASP.NET
Understanding Web Service * Property of STI
Page 4 of 14
return the details of all Web Services
uses the .vsdisco file extension
used to exclude particular folders from
the dynamic discovery process
8/8/2019 MELJUN CORTES VB.net_Understanding Web Service.net
http://slidepdf.com/reader/full/meljun-cortes-vbnetunderstanding-web-servicenet 5/14
Visual Basic .NET Programming
HTML Description PageHTML Description PageHTML Description PageHTML Description Page
and WSDL Document and WSDL Document and WSDL Document and WSDL Document
The HTML description page
describes Web services methods and
arguments
displayed when Web service URL is enteredwithout specifying a particular method
name
contains simple test utility methods
Understanding Web Service * Property of STI
Page 5 of 14
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
8/8/2019 MELJUN CORTES VB.net_Understanding Web Service.net
http://slidepdf.com/reader/full/meljun-cortes-vbnetunderstanding-web-servicenet 6/14
Visual Basic .NET Programming
HTML Description PageHTML Description PageHTML Description PageHTML Description Page
and WSDL Document and WSDL Document and WSDL Document and 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
Understanding Web Service * Property of STI
Page 6 of 14
Example:
http://localhost:3163/MyService.asmx?WSDL
8/8/2019 MELJUN CORTES VB.net_Understanding Web Service.net
http://slidepdf.com/reader/full/meljun-cortes-vbnetunderstanding-web-servicenet 7/14
Visual Basic .NET Programming
Invoking a Web ServiceInvoking a Web ServiceInvoking a Web ServiceInvoking a Web Service from a Browser from a Browser from a Browser from a Browser
and a Client and a Client and a Client and 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 STI
Page 7 of 14
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>
8/8/2019 MELJUN CORTES VB.net_Understanding Web Service.net
http://slidepdf.com/reader/full/meljun-cortes-vbnetunderstanding-web-servicenet 8/14
Visual Basic .NET Programming
Invoking a Web ServiceInvoking a Web ServiceInvoking a Web ServiceInvoking a Web Service from a Browser from a Browser from a Browser from a Browser
and a Client and a Client and a Client and 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 a lication-to-a lication
Understanding Web Service * Property of STI
Page 8 of 14
communication
difference between the HTTP-GET andSOAP
the way of sending data to the Web server
8/8/2019 MELJUN CORTES VB.net_Understanding Web Service.net
http://slidepdf.com/reader/full/meljun-cortes-vbnetunderstanding-web-servicenet 9/14
Visual Basic .NET Programming
Invoking a Web ServiceInvoking a Web ServiceInvoking a Web ServiceInvoking a Web Service from a Browser from a Browser from a Browser from a Browser
and a Client and a Client and a Client and 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 STI
Page 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
8/8/2019 MELJUN CORTES VB.net_Understanding Web Service.net
http://slidepdf.com/reader/full/meljun-cortes-vbnetunderstanding-web-servicenet 10/14
Visual Basic .NET Programming
Demo: Creating aDemo: Creating aDemo: Creating aDemo: 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
Understanding Web Service * Property of STI
Page 10 of 14
e e e e asmx e
delete the vb file
right-click on the project name and clickAdd 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
8/8/2019 MELJUN CORTES VB.net_Understanding Web Service.net
http://slidepdf.com/reader/full/meljun-cortes-vbnetunderstanding-web-servicenet 11/14
Visual Basic .NET Programming
Demo: Creating aDemo: Creating aDemo: Creating aDemo: 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
”
Understanding Web Service * Property of STI
Page 11 of 14
)> Public Class WebServiceDemo
delete the code:
<WebMethod()> _
Public Function HelloWorld()
As String
Return "Hello World"
End Function
8/8/2019 MELJUN CORTES VB.net_Understanding Web Service.net
http://slidepdf.com/reader/full/meljun-cortes-vbnetunderstanding-web-servicenet 12/14
Visual Basic .NET Programming
Demo: Creating aDemo: Creating aDemo: Creating aDemo: 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()
Understanding Web Service * Property of STI
Page 12 of 14
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
8/8/2019 MELJUN CORTES VB.net_Understanding Web Service.net
http://slidepdf.com/reader/full/meljun-cortes-vbnetunderstanding-web-servicenet 13/14
Visual Basic .NET Programming
Demo: Creating aDemo: Creating aDemo: Creating aDemo: Creating a
Web ServiceWeb ServiceWeb ServiceWeb Service
Understanding Web Service * Property of STI
Page 13 of 14
click the Service Description hyperlink
8/8/2019 MELJUN CORTES VB.net_Understanding Web Service.net
http://slidepdf.com/reader/full/meljun-cortes-vbnetunderstanding-web-servicenet 14/14
Visual Basic .NET Programming
Demo: Creating aDemo: Creating aDemo: Creating aDemo: 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 STI
Page 14 of 14
click the Invoke button