Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

ASP.NET Web Service VB

Posted on 2011-03-07
11
556 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
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 

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
 

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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Set value of dynamically created checkboxlist 2 42
Help with preventing downloading a zip file 10 45
Visual Studios 1 76
Get month and date in a format 4 32
Article by: jpaulino
XML Literals are a great way to handle XML files and the community doesn’t use it as much as it should.  An XML Literal is like a String (http://msdn.microsoft.com/en-us/library/system.string.aspx) Literal, only instead of starting and ending with w…
While working on Silverlight and WCF application, I faced one issue where fault exception occurred at WCF operation contract is not getting propagated to Silverlight client. So after searching net I came to know that it was behavior by default for s…
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

828 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