ASP.NET Web Service VB

Hey everyone running into a problem here. I have a webservice written in vb. First, I created my service already and have my default.aspx page calling the webservice without any issues. The web service goes through everything just fine and I can return my 'Arraylist".

My default.aspx page passes two parameters ("emailAddress" and "Password"). I go through all the checks and finally need to pass back two values ("UserId", and "1") if they can login and continue.

Here is the problem when I try to return the values to a label field it gives me "System.Object[]" Below is my code to show my webservice and default.aspx.vb code behind. Can anyone possibly point out what I am missing here?

'*********** START OF WEBSERVICE *******************
Imports System.Web.Services
Imports System.Web.UI
Imports System.Web.Services.Protocols
Imports System.ComponentModel
Imports AsystWebService.WebUtils
Imports System.IO
Imports System.Data
Imports System.Data.OleDb
Imports System.Data.Odbc
Imports System.Xml.Serialization
Imports System.Xml.Serialization.XmlSerializationWriter
Imports System.Collections.Generic

' To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line.
' <System.Web.Script.Services.ScriptService()> _
<System.Web.Services.WebService(Namespace:="http://www.abc.net", Description:="ABC Login Service", Name:="ABC Login Service")> _
<System.Web.Services.WebServiceBinding(ConformsTo:=WsiProfiles.BasicProfile1_1)> _
<ToolboxItem(False)> _
Public Class BoardService

    Inherits System.Web.Services.WebService
    Dim oHomeowner As clsHomeowner
    Dim oNonHomeowner As clsNonHomeowner
    Dim oStrW As New StringWriter()
    Dim sXML As String


    <WebMethod()> _
    Public Function GetandCheckBoardMemberLogin(ByVal sEmailAddress As String, ByVal sPassword As String) As ArrayList

        Try
            Dim sErrMsg As String = ""

            InitDBConnection()

            Dim nHomeownerUserID As Integer = 0
            Dim nNonHomeownerUserID As Integer = 0
            Dim nCollectorID As Integer = 0
            Dim isAHomeowner As Boolean = False
            Dim isANonHomeowner As Boolean = False
            Dim sUserType As String
            Dim iUserID As Integer

            Dim BoardItems As New ArrayList()

            Dim s As String
            Dim n As Integer
            Dim oHomeowner As New clsHomeowner(sEmailAddress.Trim, sPassword.Trim, nHomeownerUserID, s, n, n, s, n)
           
           
            Dim oNonHomeowner As New clsNonHomeowner(sEmailAddress.Trim, sPassword.Trim, nNonHomeownerUserID, nCollectorID, sUserType)
           
            Dim sStatus As String = ""

            If oHomeowner.bIsHomeowner Then
                isAHomeowner = True
                sStatus &= "You are a homeowner - you're permissions are all Good."
            Else
                sStatus &= "You are not a homeowner - you have a USERID , but not in the Owners tables."
            End If

            If oNonHomeowner.bIsANonHomeowner Then
                isANonHomeowner = True
                sStatus &= vbCrLf & "You are a Non-homeowner.  Your Acct Type is " & PrepString(oNonHomeowner.sUsrAcctType) & " - you're in Weblogin, Security Users, etc.."
            Else
                sStatus &= vbCrLf & "You are not a Non-homeowner - you're in Weblogin, but not in Security Users."
            End If


            If isAHomeowner And isANonHomeowner Then

                iUserID = nHomeownerUserID
                BoardItems.Add(Convert.ToString(iUserID))

                Dim isNonhomewner As String
                If isANonHomeowner = True Then
                    isNonhomewner = 1
                Else
                    isNonhomewner = 0
                End If
                BoardItems.Add(Convert.ToString(isNonhomewner))

                Return BoardItems

            End If

        Catch ex As Exception

        End Try
    End Function

End Class

'*********** END OF WEBSERVICE *******************

'*********** START OF DEFAULT.ASPX CODE BEHIND *******************
Imports System.Web.Services
Imports System.Web.UI
Imports System.Web.Services.Protocols
Imports System.ComponentModel
Imports System.IO
Imports System.Data
Imports System.Data.OleDb
Imports System.Data.Odbc
Imports System.Xml.Serialization
Imports System.Xml.Serialization.XmlSerializationWriter
Imports System.Collections.Generic

Imports rfBoardService
Imports System.Xml

Partial Class _Default
    Inherits System.Web.UI.Page

    

    Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim myBoardService As New rfBoardService.BoardLoginService
       
        Dim sGetEmail As String = Me.txtEmail.Text
        Dim sGetPassword As String = Me.txtPassword.Text

        Label2.Text = myBoardService.GetandCheckBoardMemberLogin(sGetEmail, sGetPassword).ToString



    End Sub
End Class

'*********** END OF DEFAULT.ASPX CODE BEHIND *******************

Open in new window

AsystDataAsked:
Who is Participating?
 
gamarrojgqCommented:
Great, glad to help, do not forget to accept the solution ;)
0
 
gamarrojgqCommented:
Hi,

I am not sure what are you expecting to get from

myBoardService.GetandCheckBoardMemberLogin(sGetEmail, sGetPassword).ToString

Since your method return an arraylist, TOSTRING method will give you something like this

System.Collections.ArrayList

If you want to return an string  (since Label2.Text property expects one) you should build one, something like

dim strArrayString as String
strArrayString = BoardItems(0) & ", " & BoardItems(0)
Return strArrayString

Hope it helps
0
 
AsystDataAuthor Commented:
Thanks for answering my question, now where do I place the code example you gave me? I placed that in my webservice class to return that string, but I still get System.Object[] when I return to my default.aspx page.

Sorry just have a little trouble understanding this since it is my first web service.
0
Cloud Class® Course: Certified Penetration Testing

This CPTE Certified Penetration Testing Engineer course covers everything you need to know about becoming a Certified Penetration Testing Engineer. Career Path: Professional roles include Ethical Hackers, Security Consultants, System Administrators, and Chief Security Officers.

 
gamarrojgqCommented:
Ok, if your GetandCheckBoardMemberLogin not need to return an ArrayList you have to change the return type to String, so instead of


    <WebMethod()> _
    Public Function GetandCheckBoardMemberLogin(ByVal sEmailAddress As String, ByVal sPassword As String) As ArrayList

Use this


    <WebMethod()> _
    Public Function GetandCheckBoardMemberLogin(ByVal sEmailAddress As String, ByVal sPassword As String) As String

Then change this code


            If isAHomeowner And isANonHomeowner Then

                iUserID = nHomeownerUserID
                BoardItems.Add(Convert.ToString(iUserID))

                Dim isNonhomewner As String
                If isANonHomeowner = True Then
                    isNonhomewner = 1
                Else
                    isNonhomewner = 0
                End If
                BoardItems.Add(Convert.ToString(isNonhomewner))

                Return BoardItems

            End If


for this one


            If isAHomeowner And isANonHomeowner Then

            Dim strReturn As String
                iUserID = nHomeownerUserID
                strReturn = Convert.ToString(iUserID)

                Dim isNonhomewner As String
                If isANonHomeowner = True Then
                    isNonhomewner = 1
                Else
                    isNonhomewner = 0
                End If
                strReturn &= "," & Convert.ToString(isNonhomewner)

                Return strReturn

            End If
0
 
AsystDataAuthor Commented:
Just before you wrote in I changed my ARRAYLIST to STRING and change some of the code. I pasted your code below and it returns a string, but in my default.aspx page it still shows up as 'SYSTEM.OBJECT[] in my label.text field. That is where I am stuck.

Any idea to what is needed from that point.
0
 
gamarrojgqCommented:
Ok, can you post the markup of your aspx file?
0
 
AsystDataAuthor Commented:

Here is the code behind and front page ASPX below.

CODE BEHIND
Imports System.Web.Services
Imports System.Web.UI
Imports System.Web.Services.Protocols
Imports System.ComponentModel
Imports System.IO
Imports System.Data
Imports System.Data.OleDb
Imports System.Data.Odbc
Imports System.Xml.Serialization
Imports System.Xml.Serialization.XmlSerializationWriter
Imports System.Collections.Generic
Imports System.Collections.ArrayList

Imports rfBoardService
Imports System.Xml

Partial Class _Default
    Inherits System.Web.UI.Page

    

    Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim myBoardService As New rfBoardService.BoardLoginService
       
        Dim sGetEmail As String = Me.txtEmail.Text
        Dim sGetPassword As String = Me.txtPassword.Text


        Label1.Text = myBoardService.GetandCheckBoardMemberLogin(sGetEmail, sGetPassword).ToString


    End Sub
End Class

'*********** FRONT PAGE DEFAULT.ASPX

<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Untitled Page</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:Button ID="Button1" runat="server" Text="Button" />
        <asp:TextBox ID="txtEmail" runat="server">bm1@asyst.net</asp:TextBox>
        <asp:TextBox ID="txtPassword" runat="server">2vv8</asp:TextBox>
        <asp:Label ID="Label2" runat="server" Text="Label"></asp:Label>
    </div>
    <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
    </form>
</body>
</html>

Open in new window

0
 
gamarrojgqCommented:
Ok, change this line

Label1.Text = myBoardService.GetandCheckBoardMemberLogin(sGetEmail, sGetPassword).ToString

for this one

Label1.Text = myBoardService.GetandCheckBoardMemberLogin(sGetEmail, sGetPassword)

that should do it
0
 
AsystDataAuthor Commented:
I tried that before and tried it again this is the error I get during debugging

BC30311: Value of type '1-dimensional array of Object' cannot be converted to 'String'.
0
 
gamarrojgqCommented:
ok, if you change the declaration of your method, maybe you need to re-compile the web service, and do not work, you probably need to remove the webservices reference and add it again after you re-compile it.

Sometimes the proxy saves the previous declarations, so, originally you method returns an 1-dimensional array, but now is returning a String, so you need to rebuild the proxy to match your new code
0
 
AsystDataAuthor Commented:
You are GOD!!!! That was it, thank you a million. I been stuck on two days with this before reaching out for help. I tried the string on my own before but to be honest I also remove the ".TOSTRING" but it still showed up as an error. When you said to remove and reference it back in that was it.

Thank again!!!!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.