Reputation: 6278
I am a newbie to handle XML response data. I have a web service which checks the user and his password in SQL server database and return the response accordingly. Code as follows for the web service method;
<WebMethod()> _
Public Function Authentication(ByVal username As String, ByVal password As String) As String
'Public Function ConnectToSQL() As String
Dim con As New SqlConnection
Dim result As Boolean
Dim response As String
Try
con.ConnectionString = "Data Source=TestServer;Initial Catalog=MyDB;Persist Security Info=True;User ID=myuser;Password=mypass"
Dim cmd As New SqlCommand("SELECT username FROM user_detail WHERE username='" + username + "' AND password='" + password + "'", con)
con.Open()
' Execute Query
Dim reader As SqlDataReader = cmd.ExecuteReader()
result = reader.HasRows
'Validate user info from database
If result = True Then
response = "Valid user info..Thanks"
Else
response = " Not valid user info..Please Enter again, Thanks"
End If
If Not reader Is Nothing Then
reader.Close()
End If
Catch ex As Exception
MessageBox.Show("Error while connecting to SQL Server." & ex.Message)
Finally
con.Close() 'Whether there is error or not. Close the connection.
End Try
Return response
End Function
End Class
The response is in XML data as shown in following fig.(if entered valid user info)
Now I want to make a view in Javascript, which take input from user and then validate user infor from database via this web service. Can some one help me how to do it?
Upvotes: 0
Views: 1371
Reputation: 9914
you can create a form that can accept username and password
and submit to your web service using javascript SOAP client.So you need to make SOAP request and pass username and password to that service where it validates .You can see examples for consuming web service is using javascript here.
http://www.guru4.net/articoli/javascript-soap-client/en/
Hope this will help you.
Upvotes: 1