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.ServicesImports System.Web.UIImports System.Web.Services.ProtocolsImports System.ComponentModelImports AsystWebService.WebUtilsImports System.IOImports System.DataImports System.Data.OleDbImports System.Data.OdbcImports System.Xml.SerializationImports System.Xml.Serialization.XmlSerializationWriterImports 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 FunctionEnd Class'*********** END OF WEBSERVICE *******************'*********** START OF DEFAULT.ASPX CODE BEHIND *******************Imports System.Web.ServicesImports System.Web.UIImports System.Web.Services.ProtocolsImports System.ComponentModelImports System.IOImports System.DataImports System.Data.OleDbImports System.Data.OdbcImports System.Xml.SerializationImports System.Xml.Serialization.XmlSerializationWriterImports System.Collections.GenericImports rfBoardServiceImports System.XmlPartial 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 SubEnd Class'*********** END OF DEFAULT.ASPX CODE BEHIND *******************
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
AsystData
ASKER
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.
gamarrojgq
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
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)
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.
gamarrojgq
Ok, can you post the markup of your aspx file?
AsystData
ASKER
Here is the code behind and front page ASPX below.CODE BEHINDImports System.Web.ServicesImports System.Web.UIImports System.Web.Services.ProtocolsImports System.ComponentModelImports System.IOImports System.DataImports System.Data.OleDbImports System.Data.OdbcImports System.Xml.SerializationImports System.Xml.Serialization.XmlSerializationWriterImports System.Collections.GenericImports System.Collections.ArrayListImports rfBoardServiceImports System.XmlPartial 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 SubEnd 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>
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'.
gamarrojgq
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
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.
I am not sure what are you expecting to get from
myBoardService.GetandCheck
Since your method return an arraylist, TOSTRING method will give you something like this
System.Collections.ArrayLi
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