Web Services
instance
This section gives you a better understanding of the appropriate instances
The use of Web services.
Any application can have Web Service components.
The creation of Web Services is independent of the kind of programming language.
One instance: Web ASP.NET web service
In this example, we'll ASP.NET to create a simple Web service.
<%@ WebService Language="VBScript" Class="TempConvert" %>
Imports System
Imports System.Web.Services
Public Class TempConvert :Inherits WebService
<WebMethod()> Public Function FahrenheitToCelsius
(ByVal Fahrenheit As String) As String
dim fahr
fahr=trim(replace(Fahrenheit,",","."))
if fahr="" or IsNumeric(fahr)=false then return "Error"
return ((((fahr) - 32) / 9) * 5)
end function
<WebMethod()> Public Function CelsiusToFahrenheit
(ByVal Celsius As String) As String
dim cel
cel=trim(replace(Celsius,",","."))
if cel="" or IsNumeric(cel)=false then return "Error"
return ((((cel) * 9) / 5) + 32)
end function
end class
This document is a .asmx file.
This is the file extension for XML Web Services ASP.NET for the file.
Instance Explained
Note:
To run this example, we need a .NET server
The first line in this document indicates that this is a Web service, written by VB, with the class name "TempConvert."
<%@ WebService Language="VBScript" Class="TempConvert" %>
The next line of code imports the namespace "System.Web.Services" from the .NET framework.
Imports System
Imports System.Web.Services
The following line defines the "TempConvert" class as a WebSerivce class:
Public Class TempConvert :Inherits WebService
The next step is basic VB programming. T
his application has two functions.
One converts Fahrenheit to Celsius, while the other converts Celsius to Fahrenheit.
The only difference from a normal application is that this function is defined as "WebMethod".
Use "WebMethod" to tag functions in applications that you want them to be web services.
<WebMethod()> Public Function FahrenheitToCelsius
(ByVal Fahrenheit As String) As String
dim fahr
fahr=trim(replace(Fahrenheit,",","."))
if fahr="" or IsNumeric(fahr)=false then return "Error"
return ((((fahr) - 32) / 9) * 5)
end function
<WebMethod()> Public Function CelsiusToFahrenheit
(ByVal Celsius As String) As String
dim cel
cel=trim(replace(Celsius,",","."))
if cel="" or IsNumeric(cel)=false then return "Error"
return ((((cel) * 9) / 5) + 32)
end function
The last thing to do is to terminate functions and classes:
If you save this file as a .asmx file and publish it on a .NET-supported server, you have the first working Web Service.
ASP.NET automated processing of the software
With ASP.NET, you don't have to write WSDL and SOAP documents yourself.
If you look closely at our example, you'll find that ASP.NET automatically create wSDL and SOAP requests.
Related tutorials
Asp.
NET tutorial