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.
Simple Web Service - Fahrenheit to Celsius in VB .NET
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.
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
|
We used over 10 web hosting companies before we found Server Intellect. Their dedicated servers
and add-ons were setup swiftly, in less than 24 hours. We were able to
confirm our order over the phone. They respond to our inquiries within
an hour. Server Intellect's customer support and assistance are the best we've ever experienced.
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" %>
|
Yes, it is possible to find a good web host. Sometimes it takes a while. After trying several, we went with Server Intellect
and have been very happy. They are the most professional, customer
service friendly and technically knowledgeable host we've found so far.
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>
|
|