There are upcoming maintenance events which may impact our services. Learn more

A Web Service example Print

  • programming, web service
  • 2

In the following example we will use ASP.NET to create a simple Web Service that converts the temperature from Fahrenheit to Celsius, and vice versa:

<%@ 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
  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
  if cel="" or IsNumeric(cel)=false then return "Error"
  return ((((cel) * 9) / 5) + 32)
end function

end class

This document is saved as an .asmx file. This is the ASP.NET file extension for XML Web Services.

Was this answer helpful?

« Back