Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Web Services > Casting Problem returning an ArrayList

Reply
Thread Tools

Casting Problem returning an ArrayList

 
 
Paul D. Fox
Guest
Posts: n/a
 
      12-07-2004
I am getting a casting issue when trying to get the results back from a web
service. Its returning an ArrayList. Anyone know how to correct this?

Private Sub btnSubmit_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnSubmit.Click

'Instantiate the Web Service
Dim GetListOfUsersADsGroupMemberships As New
wsActiveDirectoryWebReference.wsActiveDirectory
Dim arrListOfUsersGroupMemberships As ArrayList
Try

arrListOfUsersGroupMemberships =
GetListOfUsersADsGroupMemberships.ADsListUsersGrou ps(txtLoginID.Text)

arrListOfUsersGroupMemberships.Sort()
GenerateTable(CType(arrListOfUsersGroupMemberships , Object))
Catch ex As Exception
Response.Write("An exception has occurred. Please verify LoginID.")
Finally

End Try

End Sub


 
Reply With Quote
 
 
 
 
Dan Rogers
Guest
Posts: n/a
 
      12-07-2004
Hi Paul,

On the calling side, assuming you used add-web-reference, there will be an
array of some type (look at the proxy code) returned and not an array list.

This is because on the wire you cannot distinguish the two.

I hope this helps

Dan Rogers
Microsoft Corporation
--------------------
>From: "Paul D. Fox" <(E-Mail Removed)>
>Subject: Casting Problem returning an ArrayList
>Date: Tue, 7 Dec 2004 15:56:26 -0500
>Lines: 26
>X-Priority: 3
>X-MSMail-Priority: Normal
>X-Newsreader: Microsoft Outlook Express 6.00.2800.1437
>X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1441
>Message-ID: <#(E-Mail Removed)>
>Newsgroups: microsoft.public.dotnet.framework.aspnet.webservic es
>NNTP-Posting-Host: 208.49.232.106
>Path:

cpmsftngxa10.phx.gbl!TK2MSFTFEED02.phx.gbl!TK2MSFT NGP08.phx.gbl!TK2MSFTNGP09
.phx.gbl
>Xref: cpmsftngxa10.phx.gbl

microsoft.public.dotnet.framework.aspnet.webservic es:27080
>X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet.webservic es
>
>I am getting a casting issue when trying to get the results back from a web
>service. Its returning an ArrayList. Anyone know how to correct this?
>
>Private Sub btnSubmit_Click(ByVal sender As System.Object, ByVal e As
>System.EventArgs) Handles btnSubmit.Click
>
> 'Instantiate the Web Service
> Dim GetListOfUsersADsGroupMemberships As New
>wsActiveDirectoryWebReference.wsActiveDirectory
> Dim arrListOfUsersGroupMemberships As ArrayList
>Try
>
> arrListOfUsersGroupMemberships =
>GetListOfUsersADsGroupMemberships.ADsListUsersGro ups(txtLoginID.Text)
>
> arrListOfUsersGroupMemberships.Sort()
> GenerateTable(CType(arrListOfUsersGroupMemberships , Object))
>Catch ex As Exception
> Response.Write("An exception has occurred. Please verify LoginID.")
>Finally
>
>End Try
>
>End Sub
>
>
>


 
Reply With Quote
 
 
 
 
Paul D. Fox
Guest
Posts: n/a
 
      12-08-2004
Hmmm,

When I look at the proxy code, it seems to be returning an "Object". Can I
then cast it as an ArrayList at this point? Currently I get the error
message that says "Value of type '1-dimensional array of System.Object'
cannot be converted to 'system.Collections.ArrayList'.


Here is my webMethod:
'************************************************* **************************
********
'* Web Service Method: ADsListUsersGroups
'* Description: This function will return the Groups a particluar AD
User is
'* currently a member of.
'*
'* Input: LoginID As String
'* Output: ArrayList
'************************************************* **************************
********
<WebMethod(Description:="This obtains a list of groups the user is a member
of in Active Directory. Excepts LoginID As String, Returns an ArrayList of
Groups the user is a member of.")> _
Public Function ADsListUsersGroups(ByVal strLoginID As String) As
ArrayList
Dim ADsEntry1 As DirectoryEntry
Dim arrGroupMemberships As New ArrayList
'Dim arrGroupMemberships As Array

Try
ADsEntry1 = New DirectoryEntry(_DOMAIN,
ConfigurationSettings.AppSettings("ADSI_Authentica tionID"),
ConfigurationSettings.AppSettings("ADSI_Authentica tionPWD"))
Dim ADsSearch As DirectorySearcher = New
DirectorySearcher(ADsEntry1)

ADsSearch.Filter = "(&(objectClass=user)(sAMAccountName=" &
strLoginID & "*))"
Dim ADsResult As SearchResult = ADsSearch.FindOne

Dim i As Integer
Dim iCount As Integer = ADsResult.Properties("MemberOf").Count
If iCount > 0 Then
'Retrieve group membership from Windows ADs and add to
arraylist
For i = 0 To iCount - 1
Dim gADs As String =
ADsResult.Properties("MemberOf").Item(i)
Dim myGroup As String = Left(gADs, (InStr(gADs, ",") -
1))
arrGroupMemberships.Add(myGroup.Replace("CN=", ""))
'arrGroupMemberships.SetValue(myGroup.Replace("CN= ",
""), i)
Next
End If
Return arrGroupMemberships
Catch ex As Exception
Throw New System.Exception("An exception has occurred." & vbCrLf &
Err.Number & " - " & Err.Description)
Finally
End Try
End Function

Paul


"Dan Rogers" <(E-Mail Removed)> wrote in message
news(E-Mail Removed)...
> Hi Paul,
>
> On the calling side, assuming you used add-web-reference, there will be an
> array of some type (look at the proxy code) returned and not an array

list.
>
> This is because on the wire you cannot distinguish the two.
>
> I hope this helps
>
> Dan Rogers
> Microsoft Corporation
> --------------------
> >From: "Paul D. Fox" <(E-Mail Removed)>
> >Subject: Casting Problem returning an ArrayList
> >Date: Tue, 7 Dec 2004 15:56:26 -0500
> >Lines: 26
> >X-Priority: 3
> >X-MSMail-Priority: Normal
> >X-Newsreader: Microsoft Outlook Express 6.00.2800.1437
> >X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1441
> >Message-ID: <#(E-Mail Removed)>
> >Newsgroups: microsoft.public.dotnet.framework.aspnet.webservic es
> >NNTP-Posting-Host: 208.49.232.106
> >Path:

>

cpmsftngxa10.phx.gbl!TK2MSFTFEED02.phx.gbl!TK2MSFT NGP08.phx.gbl!TK2MSFTNGP09
> phx.gbl
> >Xref: cpmsftngxa10.phx.gbl

> microsoft.public.dotnet.framework.aspnet.webservic es:27080
> >X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet.webservic es
> >
> >I am getting a casting issue when trying to get the results back from a

web
> >service. Its returning an ArrayList. Anyone know how to correct this?
> >
> >Private Sub btnSubmit_Click(ByVal sender As System.Object, ByVal e As
> >System.EventArgs) Handles btnSubmit.Click
> >
> > 'Instantiate the Web Service
> > Dim GetListOfUsersADsGroupMemberships As New
> >wsActiveDirectoryWebReference.wsActiveDirectory
> > Dim arrListOfUsersGroupMemberships As ArrayList
> >Try
> >
> > arrListOfUsersGroupMemberships =
> >GetListOfUsersADsGroupMemberships.ADsListUsersGro ups(txtLoginID.Text)
> >
> > arrListOfUsersGroupMemberships.Sort()
> > GenerateTable(CType(arrListOfUsersGroupMemberships , Object))
> >Catch ex As Exception
> > Response.Write("An exception has occurred. Please verify LoginID.")
> >Finally
> >
> >End Try
> >
> >End Sub
> >
> >
> >

>



 
Reply With Quote
 
Paul D. Fox
Guest
Posts: n/a
 
      12-08-2004
Yes, the proxy code says its returning an Object (When in fact the web
service is suppose to be returning an ArrayList). In my calling code I get
an error that says "Value of type '1-dimensional array of System.Object'
cannot be converted to 'Systems.Collections.ArrayList'"

Paul

"Dan Rogers" <(E-Mail Removed)> wrote in message
news(E-Mail Removed)...
> Hi Paul,
>
> On the calling side, assuming you used add-web-reference, there will be an
> array of some type (look at the proxy code) returned and not an array

list.
>
> This is because on the wire you cannot distinguish the two.
>
> I hope this helps
>
> Dan Rogers
> Microsoft Corporation
> --------------------
> >From: "Paul D. Fox" <(E-Mail Removed)>
> >Subject: Casting Problem returning an ArrayList
> >Date: Tue, 7 Dec 2004 15:56:26 -0500
> >Lines: 26
> >X-Priority: 3
> >X-MSMail-Priority: Normal
> >X-Newsreader: Microsoft Outlook Express 6.00.2800.1437
> >X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1441
> >Message-ID: <#(E-Mail Removed)>
> >Newsgroups: microsoft.public.dotnet.framework.aspnet.webservic es
> >NNTP-Posting-Host: 208.49.232.106
> >Path:

>

cpmsftngxa10.phx.gbl!TK2MSFTFEED02.phx.gbl!TK2MSFT NGP08.phx.gbl!TK2MSFTNGP09
> phx.gbl
> >Xref: cpmsftngxa10.phx.gbl

> microsoft.public.dotnet.framework.aspnet.webservic es:27080
> >X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet.webservic es
> >
> >I am getting a casting issue when trying to get the results back from a

web
> >service. Its returning an ArrayList. Anyone know how to correct this?
> >
> >Private Sub btnSubmit_Click(ByVal sender As System.Object, ByVal e As
> >System.EventArgs) Handles btnSubmit.Click
> >
> > 'Instantiate the Web Service
> > Dim GetListOfUsersADsGroupMemberships As New
> >wsActiveDirectoryWebReference.wsActiveDirectory
> > Dim arrListOfUsersGroupMemberships As ArrayList
> >Try
> >
> > arrListOfUsersGroupMemberships =
> >GetListOfUsersADsGroupMemberships.ADsListUsersGro ups(txtLoginID.Text)
> >
> > arrListOfUsersGroupMemberships.Sort()
> > GenerateTable(CType(arrListOfUsersGroupMemberships , Object))
> >Catch ex As Exception
> > Response.Write("An exception has occurred. Please verify LoginID.")
> >Finally
> >
> >End Try
> >
> >End Sub
> >
> >
> >

>



 
Reply With Quote
 
Paul D. Fox
Guest
Posts: n/a
 
      12-10-2004
Found the issue, although I don't quite understand why since an ArrayList is serializable. What I had to do was to cast the ArrayList in the WebService's return to an Array. See the code below
'************************************************* **********************************
'* Web Service Method: ADsListUsersGroups
'* Description: This function will return the Groups a particluar AD User is
'* currently a member of.
'*
'* Input: LoginID As String
'* Output: ArrayList
'************************************************* **********************************

<WebMethod(Description:="This obtains a list of groups the user is a member of in Active Directory. Excepts LoginID As String, Returns an ArrayList of Groups the user is a member of.")> _

Public Function ADsListUsersGroups(ByVal strLoginID As String) As Array

Dim ADsEntry1 As DirectoryEntry
Dim arrGroupMemberships As New ArrayList

Try

ADsEntry1 = New DirectoryEntry(_DOMAIN, ConfigurationSettings.AppSettings("ADSI_Authentica tionID"), ConfigurationSettings.AppSettings("ADSI_Authentica tionPWD"))
Dim ADsSearch As DirectorySearcher = New DirectorySearcher(ADsEntry1)
ADsSearch.Filter = "(&(objectClass=user)(sAMAccountName=" & strLoginID & "*))"

Dim ADsResult As SearchResult = ADsSearch.FindOne
Dim i As Integer
Dim iCount As Integer = ADsResult.Properties("MemberOf").Count

If iCount > 0 Then
'Retrieve group membership from Windows ADs and add to arraylist
For i = 0 To iCount - 1
Dim gADs As String = ADsResult.Properties("MemberOf").Item(i)
Dim myGroup As String = Left(gADs, (InStr(gADs, ",") - 1))

arrGroupMemberships.Add(myGroup.Replace("CN=", ""))
Next
End If

Return arrGroupMemberships.ToArray

Catch ex As Exception
Throw New System.Exception("An exception has occurred." & vbCrLf & Err.Number & " - " & Err.Description)
Finally

End Try

End Function



Paul

"Paul D. Fox" <(E-Mail Removed)> wrote in message news:(E-Mail Removed)...
> Yes, the proxy code says its returning an Object (When in fact the web
> service is suppose to be returning an ArrayList). In my calling code I get
> an error that says "Value of type '1-dimensional array of System.Object'
> cannot be converted to 'Systems.Collections.ArrayList'"
>
> Paul
>
> "Dan Rogers" <(E-Mail Removed)> wrote in message
> news(E-Mail Removed)...
> > Hi Paul,
> >
> > On the calling side, assuming you used add-web-reference, there will be an
> > array of some type (look at the proxy code) returned and not an array

> list.
> >
> > This is because on the wire you cannot distinguish the two.
> >
> > I hope this helps
> >
> > Dan Rogers
> > Microsoft Corporation
> > --------------------
> > >From: "Paul D. Fox" <(E-Mail Removed)>
> > >Subject: Casting Problem returning an ArrayList
> > >Date: Tue, 7 Dec 2004 15:56:26 -0500
> > >Lines: 26
> > >X-Priority: 3
> > >X-MSMail-Priority: Normal
> > >X-Newsreader: Microsoft Outlook Express 6.00.2800.1437
> > >X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1441
> > >Message-ID: <#(E-Mail Removed)>
> > >Newsgroups: microsoft.public.dotnet.framework.aspnet.webservic es
> > >NNTP-Posting-Host: 208.49.232.106
> > >Path:

> >

> cpmsftngxa10.phx.gbl!TK2MSFTFEED02.phx.gbl!TK2MSFT NGP08.phx.gbl!TK2MSFTNGP09
> > phx.gbl
> > >Xref: cpmsftngxa10.phx.gbl

> > microsoft.public.dotnet.framework.aspnet.webservic es:27080
> > >X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet.webservic es
> > >
> > >I am getting a casting issue when trying to get the results back from a

> web
> > >service. Its returning an ArrayList. Anyone know how to correct this?
> > >
> > >Private Sub btnSubmit_Click(ByVal sender As System.Object, ByVal e As
> > >System.EventArgs) Handles btnSubmit.Click
> > >
> > > 'Instantiate the Web Service
> > > Dim GetListOfUsersADsGroupMemberships As New
> > >wsActiveDirectoryWebReference.wsActiveDirectory
> > > Dim arrListOfUsersGroupMemberships As ArrayList
> > >Try
> > >
> > > arrListOfUsersGroupMemberships =
> > >GetListOfUsersADsGroupMemberships.ADsListUsersGro ups(txtLoginID.Text)
> > >
> > > arrListOfUsersGroupMemberships.Sort()
> > > GenerateTable(CType(arrListOfUsersGroupMemberships , Object))
> > >Catch ex As Exception
> > > Response.Write("An exception has occurred. Please verify LoginID.")
> > >Finally
> > >
> > >End Try
> > >
> > >End Sub
> > >
> > >
> > >

> >

>
>

 
Reply With Quote
 
Dan Rogers
Guest
Posts: n/a
 
      12-10-2004
Great.

You need to remember that the type is not what comes over the wire. It is
the representation of the repeating data that has every appearance of
array. there are ways to make your proxy programming model use array
lists, but this calls for a container around your repeating elements being
represented on the wire.

Dan
--------------------
>From: "Paul D. Fox" <(E-Mail Removed)>
>References: <#(E-Mail Removed)>

<(E-Mail Removed)>
<(E-Mail Removed)>
>Subject: Re: Casting Problem returning an ArrayList
>Date: Fri, 10 Dec 2004 09:50:01 -0500
>Lines: 349
>Organization: Ascii Technologies
>MIME-Version: 1.0
>Content-Type: multipart/alternative;
> boundary="----=_NextPart_000_0009_01C4DE9D.9E38C990"
>X-Priority: 3
>X-MSMail-Priority: Normal
>X-Newsreader: Microsoft Outlook Express 6.00.2800.1437
>X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1441
>Message-ID: <O$(E-Mail Removed)>
>Newsgroups: microsoft.public.dotnet.framework.aspnet.webservic es
>NNTP-Posting-Host: 208.49.232.75
>Path:

cpmsftngxa10.phx.gbl!TK2MSFTFEED02.phx.gbl!tornado .fastwebnet.it!tiscali!new
sfeed1.ip.tiscali.net!newsfeed00.sul.t-online.de!t-online.de!TK2MSFTNGP08.ph
x.gbl!tk2msftngp13.phx.gbl
>Xref: cpmsftngxa10.phx.gbl

microsoft.public.dotnet.framework.aspnet.webservic es:27128
>X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet.webservic es
>
>Found the issue, although I don't quite understand why since an ArrayList

is serializable. What I had to do was to cast the ArrayList in the
WebService's return to an Array. See the code below
>'************************************************ **************************

*********
>'* Web Service Method: ADsListUsersGroups
>'* Description: This function will return the Groups a particluar AD User

is
>'* currently a member of.
>'*
>'* Input: LoginID As String
>'* Output: ArrayList
>'************************************************ **************************

*********
><WebMethod(Description:="This obtains a list of groups the user is a

member of in Active Directory. Excepts LoginID As String, Returns an
ArrayList of Groups the user is a member of.")> _
>Public Function ADsListUsersGroups(ByVal strLoginID As String) As Array
>Dim ADsEntry1 As DirectoryEntry
>Dim arrGroupMemberships As New ArrayList
>Try
>ADsEntry1 = New DirectoryEntry(_DOMAIN,

ConfigurationSettings.AppSettings("ADSI_Authentica tionID"),
ConfigurationSettings.AppSettings("ADSI_Authentica tionPWD"))
>Dim ADsSearch As DirectorySearcher = New DirectorySearcher(ADsEntry1)
>ADsSearch.Filter = "(&(objectClass=user)(sAMAccountName=" & strLoginID &

"*))"
>Dim ADsResult As SearchResult = ADsSearch.FindOne
>Dim i As Integer
>Dim iCount As Integer = ADsResult.Properties("MemberOf").Count
>If iCount > 0 Then
> 'Retrieve group membership from Windows ADs and add to arraylist
> For i = 0 To iCount - 1
> Dim gADs As String = ADsResult.Properties("MemberOf").Item(i)
> Dim myGroup As String = Left(gADs, (InStr(gADs, ",") - 1))
>
> arrGroupMemberships.Add(myGroup.Replace("CN=", ""))
> Next
>End If
>Return arrGroupMemberships.ToArray
>Catch ex As Exception
> Throw New System.Exception("An exception has occurred." & vbCrLf &

Err.Number & " - " & Err.Description)
>Finally
>End Try
>End Function
>Paul
>"Paul D. Fox" <(E-Mail Removed)> wrote in message

news:(E-Mail Removed)...
>> Yes, the proxy code says its returning an Object (When in fact the web
>> service is suppose to be returning an ArrayList). In my calling code I

get
>> an error that says "Value of type '1-dimensional array of System.Object'
>> cannot be converted to 'Systems.Collections.ArrayList'"
>>
>> Paul
>>
>> "Dan Rogers" <(E-Mail Removed)> wrote in message
>> news(E-Mail Removed)...
>> > Hi Paul,
>> >
>> > On the calling side, assuming you used add-web-reference, there will

be an
>> > array of some type (look at the proxy code) returned and not an array

>> list.
>> >
>> > This is because on the wire you cannot distinguish the two.
>> >
>> > I hope this helps
>> >
>> > Dan Rogers
>> > Microsoft Corporation
>> > --------------------
>> > >From: "Paul D. Fox" <(E-Mail Removed)>
>> > >Subject: Casting Problem returning an ArrayList
>> > >Date: Tue, 7 Dec 2004 15:56:26 -0500
>> > >Lines: 26
>> > >X-Priority: 3
>> > >X-MSMail-Priority: Normal
>> > >X-Newsreader: Microsoft Outlook Express 6.00.2800.1437
>> > >X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1441
>> > >Message-ID: <#(E-Mail Removed)>
>> > >Newsgroups: microsoft.public.dotnet.framework.aspnet.webservic es
>> > >NNTP-Posting-Host: 208.49.232.106
>> > >Path:
>> >

>>

cpmsftngxa10.phx.gbl!TK2MSFTFEED02.phx.gbl!TK2MSFT NGP08.phx.gbl!TK2MSFTNGP09
>> > phx.gbl
>> > >Xref: cpmsftngxa10.phx.gbl
>> > microsoft.public.dotnet.framework.aspnet.webservic es:27080
>> > >X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet.webservic es
>> > >
>> > >I am getting a casting issue when trying to get the results back from

a
>> web
>> > >service. Its returning an ArrayList. Anyone know how to correct

this?
>> > >
>> > >Private Sub btnSubmit_Click(ByVal sender As System.Object, ByVal e As
>> > >System.EventArgs) Handles btnSubmit.Click
>> > >
>> > > 'Instantiate the Web Service
>> > > Dim GetListOfUsersADsGroupMemberships As New
>> > >wsActiveDirectoryWebReference.wsActiveDirectory
>> > > Dim arrListOfUsersGroupMemberships As ArrayList
>> > >Try
>> > >
>> > > arrListOfUsersGroupMemberships =
>> > >GetListOfUsersADsGroupMemberships.ADsListUsersGro ups(txtLoginID.Text)
>> > >
>> > > arrListOfUsersGroupMemberships.Sort()
>> > > GenerateTable(CType(arrListOfUsersGroupMemberships , Object))
>> > >Catch ex As Exception
>> > > Response.Write("An exception has occurred. Please verify

LoginID.")
>> > >Finally
>> > >
>> > >End Try
>> > >
>> > >End Sub
>> > >
>> > >
>> > >
>> >

>>
>>

>


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Clear Arraylist vs new ArrayList Philipp Java 6 05-28-2008 09:07 PM
Does the clone() method of ArrayList<> make a copy of the objects in the ArrayList? xz Java 16 08-04-2007 10:33 PM
a class inherited from ArrayList, is saved to ViewState, why the type of the object read from ViewSate is not the class, but the parent, ArrayList leal ting ASP .Net 1 02-10-2004 07:45 PM
writeObject with ArrayList of ArrayList? Kaidi Java 4 01-03-2004 08:16 PM
Iterate through ArrayList using an another ArrayList Saravanan Rathinavelu ASP .Net 3 08-19-2003 07:03 AM



Advertisments