The web service converts a Fahrenheit Temperature into Celsius.
Here's the server source code:
Here's the client source code:Code:Imports System.Web.Services <System.Web.Services.WebService(Namespace:="http://localhost/Test1/Service1")> _ Public Class Service1 Inherits System.Web.Services.WebService #Region " Web Services Designer Generated Code " Public Sub New() MyBase.New() 'This call is required by the Web Services Designer. InitializeComponent() 'Add your own initialization code after the InitializeComponent() call End Sub 'Required by the Web Services Designer Private components As System.ComponentModel.IContainer 'NOTE: The following procedure is required by the Web Services Designer 'It can be modified using the Web Services Designer. 'Do not modify it using the code editor. <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent() components = New System.ComponentModel.Container End Sub Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean) 'CODEGEN: This procedure is required by the Web Services Designer 'Do not modify it using the code editor. If disposing Then If Not (components Is Nothing) Then components.Dispose() End If End If MyBase.Dispose(disposing) End Sub #End Region ' WEB SERVICE EXAMPLE ' The HelloWorld() example service returns the string Hello World. ' To build, uncomment the following lines then save and build the project. ' To test this web service, ensure that the .asmx file is the start page ' and press F5. ' '<WebMethod()> _ 'Public Function HelloWorld() As String ' Return "Hello World" 'End Function <WebMethod(Description:="This method converts a temperature in " & _ "degrees Fahrenheit to a temperature in degrees Celsius.")> _ Public Function ConvertTemperature(ByVal dFahrenheit As Double) _ As Double Return ((dFahrenheit - 32) * 5) / 9 End Function End Class
When running the application, code execution always skips to the Catch block after the line dCelsius = ws.ConvertTemperature(dFahrenheit).Code:Public Class WebForm1 Inherits System.Web.UI.Page #Region " Web Form Designer Generated Code " 'This call is required by the Web Form Designer. <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent() End Sub Protected WithEvents TextBox1 As System.Web.UI.WebControls.TextBox Protected WithEvents Label1 As System.Web.UI.WebControls.Label Protected WithEvents Button1 As System.Web.UI.WebControls.Button 'NOTE: The following placeholder declaration is required by the Web Form Designer. 'Do not delete or move it. Private designerPlaceholderDeclaration As System.Object Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init 'CODEGEN: This method call is required by the Web Form Designer 'Do not modify it using the code editor. InitializeComponent() End Sub #End Region Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load 'Put user code to initialize the page here End Sub Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim ws As New ConvertSvc.Service1 Dim dFahrenheit As Double Dim dCelsius As Double Try dFahrenheit = Convert.ToDouble(TextBox1.Text) dCelsius = ws.ConvertTemperature(dFahrenheit) Label1.Text = dCelsius.ToString() Catch Label1.Text = "Conversion failed." End Try End Sub End Class
Any ideas what's going on?





Reply With Quote