Solved

ASP.NET Web Service VB

Posted on 2011-03-07
11
546 Views
Last Modified: 2012-06-21
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

0
Comment
Question by:AsystData
  • 6
  • 5
11 Comments
 
LVL 13

Expert Comment

by:gamarrojgq
ID: 35061293
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
 

Author Comment

by:AsystData
ID: 35061653
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
 
LVL 13

Expert Comment

by:gamarrojgq
ID: 35061733
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
 

Author Comment

by:AsystData
ID: 35061836
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
 
LVL 13

Expert Comment

by:gamarrojgq
ID: 35061895
Ok, can you post the markup of your aspx file?
0
What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

 

Author Comment

by:AsystData
ID: 35061915

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
 
LVL 13

Expert Comment

by:gamarrojgq
ID: 35061997
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
 

Author Comment

by:AsystData
ID: 35062023
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
 
LVL 13

Expert Comment

by:gamarrojgq
ID: 35062075
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
 

Author Comment

by:AsystData
ID: 35062146
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
 
LVL 13

Accepted Solution

by:
gamarrojgq earned 500 total points
ID: 35062177
Great, glad to help, do not forget to accept the solution ;)
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Since .Net 2.0, Visual Basic has made it easy to create a splash screen and set it via the "Splash Screen" drop down in the Project Properties.  A splash screen set in this manner is automatically created, displayed and closed by the framework itsel…
It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

746 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now