R
rn5a
I have created the following WebService named NConnect.asmx using which
I want an ASPX page to first authenticate a user & after successful
user validation, the ASPX page should display a few TextBoxes for users
to enter some data in those TextBoxes which will finally be inserted in
a SQL Server 2005 DB table:
<%@ WebService Language="VB" Class="NConnect" %>
Imports System
Imports System.Data
Imports System.Data.SqlClient
Imports System.Web
Imports System.Web.Services
Imports System.Web.Services.Protocols
Public Class Authenticator : Inherits SoapHeader
Public UserName As String
Public Password As String
End Class
Public Class NConnect : Inherits WebService
Public sHeader As Authenticator
Private sqlConn As New SqlConnection(".......")
<WebMethod(), SoapHeader("sHeader")> Public Sub UpdateData(ByVal
UserID As Integer, ByVal Mileage As Double, ByVal MaxSpeed As Double,
ByVal Throttle As Double)
If (sHeader Is Nothing) Then
Throw New ArgumentNullException
End If
If (Authenticate(sHeader.UserName, sHeader.Password)) Then
Dim sqlCmd As SqlCommand
sqlCmd = New SqlCommand("ConnectInfo", sqlConn)
sqlCmd.CommandType = CommandType.StoredProcedure
Try
With sqlCmd
.Parameters.Add("@UserID", SqlDbType.Int).Value =
UserID
'passing other parameters to the
'SP to be inserted in the DB table
End With
sqlConn.Open()
sqlCmd.ExecuteNonQuery()
Catch ex As SqlException
Throw ex
End Try
End If
End Sub
Private Function Authenticate(ByVal UserName As String, ByVal
Password As String) As Boolean
Dim iUID As Integer = 0
Dim sqlCmd As SqlCommand
sqlCmd = New SqlCommand("ValidateUser", sqlConn)
sqlCmd.CommandType = CommandType.StoredProcedure
With sqlCmd
.Parameters.Add("@username", SqlDbType.VarChar, 50).Value =
UserName
.Parameters.Add("@Password", SqlDbType.VarChar, 50).Value =
Password
End With
sqlConn.Open()
iUID = CType(sqlCmd.ExecuteScalar, Integer)
If (iUID = 0) Then
Return False
Else
Return True
End If
End Function
End Class
Now how do I make use of the above ASMX Web Service in an ASPX page so
that ASP.NET first validates the user, then renders a few TextBoxes for
the user to enter some data which will finally be inserted a DB table
when the user clicks a Button?
How do I pass the UserName & Password as the SOAP headers so as to send
the SOAP headers to validate the user?
If I type the URL http://myserver/ASPX/NConnect.asmx?op=UpdateData in
the browser, then the browser displays the 4 TextBoxes which are the 4
parameters the WebMethod UpdataData expects but how do I validate the
user prior to that?
Apart from the 4 TextBoxes, the above URL also displays info about SOAP
& all those things. How do I avoid that?
The bottomline is whatever tasks the above ASMX code does, I want do
them in an ASPX page using the ASMX code.
I want an ASPX page to first authenticate a user & after successful
user validation, the ASPX page should display a few TextBoxes for users
to enter some data in those TextBoxes which will finally be inserted in
a SQL Server 2005 DB table:
<%@ WebService Language="VB" Class="NConnect" %>
Imports System
Imports System.Data
Imports System.Data.SqlClient
Imports System.Web
Imports System.Web.Services
Imports System.Web.Services.Protocols
Public Class Authenticator : Inherits SoapHeader
Public UserName As String
Public Password As String
End Class
Public Class NConnect : Inherits WebService
Public sHeader As Authenticator
Private sqlConn As New SqlConnection(".......")
<WebMethod(), SoapHeader("sHeader")> Public Sub UpdateData(ByVal
UserID As Integer, ByVal Mileage As Double, ByVal MaxSpeed As Double,
ByVal Throttle As Double)
If (sHeader Is Nothing) Then
Throw New ArgumentNullException
End If
If (Authenticate(sHeader.UserName, sHeader.Password)) Then
Dim sqlCmd As SqlCommand
sqlCmd = New SqlCommand("ConnectInfo", sqlConn)
sqlCmd.CommandType = CommandType.StoredProcedure
Try
With sqlCmd
.Parameters.Add("@UserID", SqlDbType.Int).Value =
UserID
'passing other parameters to the
'SP to be inserted in the DB table
End With
sqlConn.Open()
sqlCmd.ExecuteNonQuery()
Catch ex As SqlException
Throw ex
End Try
End If
End Sub
Private Function Authenticate(ByVal UserName As String, ByVal
Password As String) As Boolean
Dim iUID As Integer = 0
Dim sqlCmd As SqlCommand
sqlCmd = New SqlCommand("ValidateUser", sqlConn)
sqlCmd.CommandType = CommandType.StoredProcedure
With sqlCmd
.Parameters.Add("@username", SqlDbType.VarChar, 50).Value =
UserName
.Parameters.Add("@Password", SqlDbType.VarChar, 50).Value =
Password
End With
sqlConn.Open()
iUID = CType(sqlCmd.ExecuteScalar, Integer)
If (iUID = 0) Then
Return False
Else
Return True
End If
End Function
End Class
Now how do I make use of the above ASMX Web Service in an ASPX page so
that ASP.NET first validates the user, then renders a few TextBoxes for
the user to enter some data which will finally be inserted a DB table
when the user clicks a Button?
How do I pass the UserName & Password as the SOAP headers so as to send
the SOAP headers to validate the user?
If I type the URL http://myserver/ASPX/NConnect.asmx?op=UpdateData in
the browser, then the browser displays the 4 TextBoxes which are the 4
parameters the WebMethod UpdataData expects but how do I validate the
user prior to that?
Apart from the 4 TextBoxes, the above URL also displays info about SOAP
& all those things. How do I avoid that?
The bottomline is whatever tasks the above ASMX code does, I want do
them in an ASPX page using the ASMX code.