Click to See Complete Forum and Search --> : retrieving data from a webservice
M.L.Srinivas
March 10th, 2005, 12:41 AM
Hi all,
This is my first task with web services and quite new .NET.
I tried a test webservice with "hello world" and "addnum" functions. When I tested them, they worked fine. Then in the same service I added webmethods which interact with database and returns me the output.
When I execute these methods while testing, I'm getting "Page cannot be displayed" in browser.
How to locate the problem? And what could be the problem?
Please help.
thanks
-srinivas
marker
March 10th, 2005, 06:58 PM
If you are having problem in accesing local database.
UserName and Password to access the database should be either windows authenticate or different username/Password.
Settings->Control Panel->Administrative Tools->IIS
IIS Dialog will open,
Choose the server ( should be computer name if its local )
Web sites->Default web sites
Find the project you created
Right click to properties
Directory Security->Edit
Uncheck the Anonymous
Now your application should work with database.
Take it easy
Marker
M.L.Srinivas
March 10th, 2005, 11:14 PM
Hi Marker,
thanks for your time. I have done the changes you suggested. But it did not work out.
I'm using local database.
Here is my code:
Imports System.Web.Services
Imports System.Data
Imports System.Data.SqlClient
<System.Web.Services.WebService(Namespace:="http://MyWebSerives/DataTest/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()> Public Function GetData() As DataSet
Dim SqlCon As New SqlConnection
Dim constr As String
constr = "Provider=SQLOLEDB.1;Password=manager;Persist Security Info=False;User ID=sa;Initial Catalog=TransAidDB;Data Source=soft"
SqlCon.ConnectionString = constr
Try
SqlCon.Open()
Dim sqlcmd As SqlDataAdapter
sqlcmd = New SqlDataAdapter("select* from ratedetails", SqlCon)
Dim aut As New DataSet
sqlcmd.Fill(aut, "Ratedetails")
Return aut
Catch ex As System.Exception
MsgBox(ex.Message)
Finally
SqlCon.Close()
End Try
End Function
End Class
And also please check the attachment for output.
thanks
-srinivas
prachipurwar
March 12th, 2005, 01:58 AM
Hi,
I think you cannot use msgbox in asp.net and you are returning dataset in try block but if code gets any error in try block statement then it is showing a messagebox(which is invalid in asp.net) and it is not returing anyvalue. So please change your code.
Regards,
Prachi
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.