473,396 Members | 1,784 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Using WebService In ASPX

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.

Oct 10 '06 #1
2 2556
Hi,

rn**@rediffmail.com wrote:
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:
<snip>

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?
This is only a service provided by ASP.NET, to allow you testing your
web service code without implementing a client. When you deploy the web
service to the production server, the ASP.NET won't deliver this feature
anymore, this is only in localhost configuration.
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.
If you want the client to call the ASMX web service, you must implement
a client in JavaScript. Implementing the SOAP client yourself is
possible but difficult. There are frameworks for that. Check atlas.asp.net.

If you want to call the web service from your server-side code (i.e.
when the page is rendered, it connects to the web service, gets
information and then use this information to render the HTML code), then
you can use Web References in Studio 2005. Simply right click on your
project, choose "Add web reference", and then enter the web service's
URL and follow the instructions. This will create a proxy class, which
you can use in your code behind in synchronous or asynchronous way.

Finally, as usual, you might want to ask yourself if a SOAP based web
service is really what you need, and might be interested in reading this:
http://www.galasoft-lb.ch/mydotnet/a...006100601.aspx

HTH,
Laurent
--
Laurent Bugnion, GalaSoft
Software engineering: http://www.galasoft-LB.ch
Private/Malaysia: http://mypage.bluewin.ch/lbugnion
Support children in Calcutta: http://www.calcutta-espoir.ch
Oct 10 '06 #2
First thing I see is a real design problem.

In general, you should not mix metaphors. In other words, authentication and
putting data in the database are two separate operations. While you can
combine them into one message, you have to return a message to let hte user
know precisely what happened. For example, did I fail putting information
into hte database, fail to authenticate, or raise an exception? Which
happened? The way you have things designed, you will never know.

Now, you can get around this with logging, but it still misses the point.

My suggestion. Two paths:

Path 1: Make your service look more like a typical library. Separate the
authentication method from the insert method and roll in that direction.

Path 2: If it makes sense to combine the information, use a message based
approach and send all of the information and return a message to indicate
what happened when the person called the method. As a sub, you return void.

As for calling the service, you can create a web reference. In ASP.NET 2.0,
where you can easily rename services, you can point to an ASMX in the same
project (although that would be unwise performance wise and I would,
instead, encapsulate the logic in a library and call from both the ASPX and
the ASMX, depending on how the user is using the system).

EIther way, I would move the actual funcationality out of the UI, whether
the "UI" is ASPX or ASMX. This gives you much better reuse.

Good luck!

--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA
http://gregorybeamer.spaces.live.com

*************************************************
Think outside of the box!
*************************************************
<rn**@rediffmail.comwrote in message
news:11**********************@h48g2000cwc.googlegr oups.com...
>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.

Oct 10 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Holly | last post by:
Hi, I have a page (A) that allows users to enter addresses and displays direction information and map images. The page A calls Microsoft's mappoint web service, gets the route info and map image....
0
by: Nalla | last post by:
Hi, I have a requirement to call webservices from my old C++ application.So first I tried with Vc++.net as follows.....There are 2 approach Dotnet frame work and soaptoolkit 3.0 I am not able to...
5
by: David Lozzi | last post by:
Howdy, I wrote a web service in .Net for my customer. My customer has another vendor who now has to consume it but they are not using Visual Studio. Most of their pages are jsp, and they said...
0
by: batista | last post by:
Hello all, I am using a webpage having a grid and im calling a webservice method(using webservice.htc) which after 5 seconds updates the content of the grid, uptil now everything is working...
0
by: Andrew | last post by:
hi all, My app works fine on my localhost. I just uploaded my folders n files containing my aspx files onto the server. My aspx app consumes a webservice also on the same server. In my...
4
by: =?Utf-8?B?QmlsbEF0V29yaw==?= | last post by:
Hi, We recently converted a 1.1 project to 2.0 and this included a webservice which accepted XML for one of the parameters. Since converting to 2.0 I am getting the following message: --- A...
1
by: =?Utf-8?B?d2R1ZGVr?= | last post by:
I have a web service hosting a WCF library, which works fine but produced a strange signature when interacting with vs 2005/2.0 clients. My method takes 3 strings and returns a bool as below. ...
4
by: Jonathan | last post by:
I have a SQL stored procedure for adding a new record in a transactions table. It also has two return values: CounterID and IDKey. I want to create a webservice that accepts the 10 input...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.