Server Intellect
 
Home   Asp.Net Tutorials   What's New   Newsletter   More Resources
 
 
  Categories
Advanced Technologies
AJAX
Internet Browsers
Controls
Database
Email
Error Handling
File
Graphics
Website Navigation
Network
Performance
User Interface and Themes
Validation
Visual Web Developer
Web Services
XML
Suggest Tutorial


Navigator: Home - Tutorials - Web Services - Simple Web Service - Fahrenheit to Celsius in VB .NET
Simple Web Service - Fahrenheit to Celsius in VB .NET


ASP.NET Web Services Tutorial

This tutorial will show how we can create a Web Service that will allow us to convert from Fahrenheit to Celsius, or vice versa. VB version.

Download the Full Working Version of this Project written with Visual Studio.NET VB 2005 Here!

Looking for the C#.NET 2005 Version? Click Here!

Looking for more ASP.NET Tutorials? Click Here!

Web Services allow you to use applications in your Web Project. In this demonstration, we will show how we can easily implement an application into our Web Project. We will write two simple methods that will enable us to convert Fahrenheit into Celsius, and vice versa. The methods will be the Web Service, and theoretically, be stored on a different web server than our Web Project that is using it.

First, we start off with a Web Service Porject in Visual Studio .NET
Then we will add the logic to the App_Code folder, in the .vb file:

Imports System.Web
Imports System.Web.Services
Imports System.Web.Services.Protocols

<WebService(Namespace:="http://tempuri.org/")> _
<WebServiceBinding(ConformsTo:=WsiProfiles.BasicProfile1_1)> _
<Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _
Public Class Service
Inherits System.Web.Services.WebService

<WebMethod()> _
Public Function HelloWorld() As String
Return "Hello World"
End Function

<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

Here, there are three methods. One is the simple Hello World method, which will retrieve a string when called. The other two will convert a number into either Fahrenheit or Celsius, depending on which method is called.
The Service.asmx file will look something like this:

<%@ WebService Language="vb" CodeBehind="~/App_Code/Service.vb" Class="Service" %>

We now need a form to call the Web Service, as well as send the number to convert. For this, we create a web form and allow the user to either convert from Fahrenheit to Celsius, or Celsius to Fahrenheit.
The ASPX page should look something like the following:

<form target="_blank" action="Service.asmx/FahrenheitToCelsius" method="POST">
<table>
<tr>
<td>Fahrenheit to Celsius:</td>
<td><input class="frmInput" type="text"
size="30" name="Fahrenheit"></td>
</tr>
<tr>
<td></td>
<td align="right"> <input type="submit" value="Submit" class="button"></td>
</tr>
</table>
</form>

<form target="_blank" action="Service.asmx/CelsiusToFahrenheit" method="POST">
<table>
<tr>
<td>Celsius to Fahrenheit:</td>
<td><input class="frmInput" type="text"
size="30" name="Celsius"></td>
</tr>
<tr>
<td></td>
<td align="right"> <input type="submit" value="Submit" class="button"></td>
</tr>
</table>
</form>

Download the Full Working Version of this Project written with Visual Studio.NET VB 2005 Here!

Looking for the C#.NET 2005 Version? Click Here!

Looking for more ASP.NET Tutorials? Click Here!







 
  Developer Resources







Server Intellect Rocks