|
-
Mar 17th, 2004, 11:21 AM
#1
Thread Starter
Fanatic Member
*Resolved* Web Service in App and Browser
Hi and thanks for reading.
I'm trying to get a simple web service to work and have encountered a very weird problem. The web service works just fine in the browser but won't work in my app! Actually, I've tried creating multiple web services and consuming them with VB.Net, ASP.Net, Managed C++, etc. and I keep having the same problem: the web service ALWAYS works in the browser but NEVER in the app. I'm sure there is a simple fix for this but I can't find it. Can anyone point me in the right direction?
Thanks!
Last edited by OneSource; Mar 18th, 2004 at 10:38 AM.
-
Mar 17th, 2004, 07:27 PM
#2
Hyperactive Member
Maybe describing the problem is a good place to start. What are you trying to do(specifics, code examples, etc)? any exceptions?
-
Mar 18th, 2004, 09:24 AM
#3
Thread Starter
Fanatic Member
The web service converts a Fahrenheit Temperature into Celsius.
Here's the server 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
Here's the client source code:
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
When running the application, code execution always skips to the Catch block after the line dCelsius = ws.ConvertTemperature(dFahrenheit). 
Any ideas what's going on?
-
Mar 18th, 2004, 09:36 AM
#4
Hyperactive Member
I tried your code and it worked like a champ. If you're getting and exception you'll want something like this to find out what it's complaining about:
VB Code:
Try
dFahrenheit = Convert.ToDouble(TextBox1.Text)
dCelsius = ws.ConvertTemperature(dFahrenheit)
Label1.Text = dCelsius.ToString()
Catch ex As Exception
Label1.Text = ex.Message
End Try
-
Mar 18th, 2004, 10:37 AM
#5
Thread Starter
Fanatic Member
Thanks ...
pvb! With your error handling example, I was able to determine that there was an issue with the "Anonymous access authentication" for the web service. Once I addressed this in IIS, everything worked "like a champ" for me too! 
Thanks again,
OneSource
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|