By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,491 Members | 1,191 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,491 IT Pros & Developers. It's quick & easy.

passing an arrayList to web service

P: n/a
I have a following structure that I am using with array list:
Private Structure arrayliststruct
Public Name As String
Public value As String
Public type As String
End Structure

and following function to format arraylist the way I want and calling it
from button click event:
Private Function formatarray(ByVal inarray As ArrayList, _
ByVal inName As String, _
ByVal initem As String, _
ByVal initemtype As String)

Dim arrayparam As arrayliststruct

arrayparam.Name = inName
arrayparam.value = initem
arrayparam.type = initemtype
inarray.Add(arrayparam)

Return inarray

End Function

I have follwoing code in button click event

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

Dim inarray As New ArrayList
inarray = formatarray(inarray, "Email", "my*****@email.com", "String")
inarray = formatarray(inarray, "Name", "My Name", "String")

' then I want to pass this code to web serivce that accepts arrary list
Dim postEv As New testev.wsTEST
postEv.Credentials = Net.CredentialCache.DefaultCredentials
postEv.PreAuthenticate = True
postEv.PostExtEvent("Test", "Source", inarray(2))

End Sub

I don't know how to pass arraylist to a webservice.
please help:
Nov 7 '06 #1
Share this Question
Share on Google+
8 Replies


P: n/a
I don't want to pass arralylist index with the arrary list and I am getting
follwoing errors
1if passed without index
"number of indices is less than the number of dimensions"

2if passed with index
Index was out of range. Must be non-negative and less than the size of the
collection.
Parameter name: index

"amazon" wrote:
I have a following structure that I am using with array list:
Private Structure arrayliststruct
Public Name As String
Public value As String
Public type As String
End Structure

and following function to format arraylist the way I want and calling it
from button click event:
Private Function formatarray(ByVal inarray As ArrayList, _
ByVal inName As String, _
ByVal initem As String, _
ByVal initemtype As String)

Dim arrayparam As arrayliststruct

arrayparam.Name = inName
arrayparam.value = initem
arrayparam.type = initemtype
inarray.Add(arrayparam)

Return inarray

End Function

I have follwoing code in button click event

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

Dim inarray As New ArrayList
inarray = formatarray(inarray, "Email", "my*****@email.com", "String")
inarray = formatarray(inarray, "Name", "My Name", "String")

' then I want to pass this code to web serivce that accepts arrary list
Dim postEv As New testev.wsTEST
postEv.Credentials = Net.CredentialCache.DefaultCredentials
postEv.PreAuthenticate = True
postEv.PostExtEvent("Test", "Source", inarray(2))

End Sub

I don't know how to pass arraylist to a webservice.
please help:

Nov 7 '06 #2

P: n/a
The function:
Private Function formatarray(ByVal inarray As ArrayList, _
ByVal inName As String, _
ByVal initem As String, _
ByVal initemtype As String)

Isn't declared as anything, presumably you want:

Private Function formatarray(ByVal inarray As ArrayList, _
ByVal inName As String, _
ByVal initem As String, _
ByVal initemtype As String) As
ArrayList

Don't know if that is a typo or if it will fix your problem. If it does not
fix the problem you might like to post the declaration for the webservice
function also.

"amazon" <am****@discussions.microsoft.comwrote in message
news:5E**********************************@microsof t.com...
>I don't want to pass arralylist index with the arrary list and I am getting
follwoing errors
1if passed without index
"number of indices is less than the number of dimensions"

2if passed with index
Index was out of range. Must be non-negative and less than the size of the
collection.
Parameter name: index

"amazon" wrote:
>I have a following structure that I am using with array list:
Private Structure arrayliststruct
Public Name As String
Public value As String
Public type As String
End Structure

and following function to format arraylist the way I want and calling it
from button click event:
Private Function formatarray(ByVal inarray As ArrayList, _
ByVal inName As String, _
ByVal initem As String, _
ByVal initemtype As String)

Dim arrayparam As arrayliststruct

arrayparam.Name = inName
arrayparam.value = initem
arrayparam.type = initemtype
inarray.Add(arrayparam)

Return inarray

End Function

I have follwoing code in button click event

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

Dim inarray As New ArrayList
inarray = formatarray(inarray, "Email", "my*****@email.com", "String")
inarray = formatarray(inarray, "Name", "My Name", "String")

' then I want to pass this code to web serivce that accepts arrary list
Dim postEv As New testev.wsTEST
postEv.Credentials = Net.CredentialCache.DefaultCredentials
postEv.PreAuthenticate = True
postEv.PostExtEvent("Test", "Source", inarray(2))

End Sub

I don't know how to pass arraylist to a webservice.
please help:


Nov 7 '06 #3

P: n/a
Thnaks Joseph

Thanks for reply..

I changed the function and declared as
Private Function formatarray(ByVal inarray As ArrayList, _
ByVal inName As String, _
ByVal initem As String, _
ByVal initemtype As String) As ArrayList

Stil the same problem..

my web service is

Public Sub PostExtEvent(ByVal EventName As String, ByVal ExternalSource As
String, ByVal inparam As ArrayList)

Thanks

"JosephByrns" wrote:
The function:
Private Function formatarray(ByVal inarray As ArrayList, _
ByVal inName As String, _
ByVal initem As String, _
ByVal initemtype As String)

Isn't declared as anything, presumably you want:

Private Function formatarray(ByVal inarray As ArrayList, _
ByVal inName As String, _
ByVal initem As String, _
ByVal initemtype As String) As
ArrayList

Don't know if that is a typo or if it will fix your problem. If it does not
fix the problem you might like to post the declaration for the webservice
function also.

"amazon" <am****@discussions.microsoft.comwrote in message
news:5E**********************************@microsof t.com...
I don't want to pass arralylist index with the arrary list and I am getting
follwoing errors
1if passed without index
"number of indices is less than the number of dimensions"

2if passed with index
Index was out of range. Must be non-negative and less than the size of the
collection.
Parameter name: index

"amazon" wrote:
I have a following structure that I am using with array list:
Private Structure arrayliststruct
Public Name As String
Public value As String
Public type As String
End Structure

and following function to format arraylist the way I want and calling it
from button click event:
Private Function formatarray(ByVal inarray As ArrayList, _
ByVal inName As String, _
ByVal initem As String, _
ByVal initemtype As String)

Dim arrayparam As arrayliststruct

arrayparam.Name = inName
arrayparam.value = initem
arrayparam.type = initemtype
inarray.Add(arrayparam)

Return inarray

End Function

I have follwoing code in button click event

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

Dim inarray As New ArrayList
inarray = formatarray(inarray, "Email", "my*****@email.com", "String")
inarray = formatarray(inarray, "Name", "My Name", "String")

' then I want to pass this code to web serivce that accepts arrary list
Dim postEv As New testev.wsTEST
postEv.Credentials = Net.CredentialCache.DefaultCredentials
postEv.PreAuthenticate = True
postEv.PostExtEvent("Test", "Source", inarray(2))

End Sub

I don't know how to pass arraylist to a webservice.
please help:



Nov 7 '06 #4

P: n/a
I found some info on:
http://support.microsoft.com/default.aspx/kb/814320

and changed inarray(2) to inarray(0)

my web service is
Public Sub PostExtEvent(ByVal EventName As String, ByVal ExternalSource As
String, ByVal inparam As ArrayList)

this is how I see it when try to call
PostExtEvent(EventName as string, ExternalSource as string, inparam() as
object

and I get error message as:
Unable to cast object of type 'arrayliststruct' to type 'System.Object[]'.

Thanks//
"amazon" wrote:
Thnaks Joseph

Thanks for reply..

I changed the function and declared as
Private Function formatarray(ByVal inarray As ArrayList, _
ByVal inName As String, _
ByVal initem As String, _
ByVal initemtype As String) As ArrayList

Stil the same problem..

my web service is

Public Sub PostExtEvent(ByVal EventName As String, ByVal ExternalSource As
String, ByVal inparam As ArrayList)

Thanks

"JosephByrns" wrote:
The function:
Private Function formatarray(ByVal inarray As ArrayList, _
ByVal inName As String, _
ByVal initem As String, _
ByVal initemtype As String)

Isn't declared as anything, presumably you want:

Private Function formatarray(ByVal inarray As ArrayList, _
ByVal inName As String, _
ByVal initem As String, _
ByVal initemtype As String) As
ArrayList

Don't know if that is a typo or if it will fix your problem. If it does not
fix the problem you might like to post the declaration for the webservice
function also.

"amazon" <am****@discussions.microsoft.comwrote in message
news:5E**********************************@microsof t.com...
>I don't want to pass arralylist index with the arrary list and I am getting
follwoing errors
1if passed without index
"number of indices is less than the number of dimensions"
>
2if passed with index
Index was out of range. Must be non-negative and less than the size of the
collection.
Parameter name: index
>
"amazon" wrote:
>
>I have a following structure that I am using with array list:
>Private Structure arrayliststruct
> Public Name As String
> Public value As String
> Public type As String
>End Structure
>>
>and following function to format arraylist the way I want and calling it
>from button click event:
>Private Function formatarray(ByVal inarray As ArrayList, _
> ByVal inName As String, _
> ByVal initem As String, _
> ByVal initemtype As String)
>>
> Dim arrayparam As arrayliststruct
>>
> arrayparam.Name = inName
> arrayparam.value = initem
> arrayparam.type = initemtype
> inarray.Add(arrayparam)
>>
> Return inarray
>>
>End Function
>>
>I have follwoing code in button click event
>>
>Protected Sub btnSubmit_Click(ByVal sender As Object, ByVal e As
>System.EventArgs) Handles btnSubmit.Click
>>
>Dim inarray As New ArrayList
>inarray = formatarray(inarray, "Email", "my*****@email.com", "String")
>inarray = formatarray(inarray, "Name", "My Name", "String")
>>
>' then I want to pass this code to web serivce that accepts arrary list
>Dim postEv As New testev.wsTEST
>postEv.Credentials = Net.CredentialCache.DefaultCredentials
>postEv.PreAuthenticate = True
>postEv.PostExtEvent("Test", "Source", inarray(2))
>>
>End Sub
>>
>I don't know how to pass arraylist to a webservice.
>please help:
>>
>>
Nov 7 '06 #5

P: n/a
You should just be calling it like:

postEv.PostExtEvent("Test", "Source", inarray)

without the brackets or index, does it still not work then?

"amazon" <am****@discussions.microsoft.comwrote in message
news:3D**********************************@microsof t.com...
Thnaks Joseph

Thanks for reply..

I changed the function and declared as
Private Function formatarray(ByVal inarray As ArrayList, _
ByVal inName As String, _
ByVal initem As String, _
ByVal initemtype As String) As
ArrayList

Stil the same problem..

my web service is

Public Sub PostExtEvent(ByVal EventName As String, ByVal ExternalSource As
String, ByVal inparam As ArrayList)

Thanks

"JosephByrns" wrote:
>The function:
Private Function formatarray(ByVal inarray As ArrayList, _
ByVal inName As String, _
ByVal initem As String, _
ByVal initemtype As String)

Isn't declared as anything, presumably you want:

Private Function formatarray(ByVal inarray As ArrayList, _
ByVal inName As String, _
ByVal initem As String, _
ByVal initemtype As String) As
ArrayList

Don't know if that is a typo or if it will fix your problem. If it does
not
fix the problem you might like to post the declaration for the webservice
function also.

"amazon" <am****@discussions.microsoft.comwrote in message
news:5E**********************************@microso ft.com...
>I don't want to pass arralylist index with the arrary list and I am
getting
follwoing errors
1if passed without index
"number of indices is less than the number of dimensions"

2if passed with index
Index was out of range. Must be non-negative and less than the size of
the
collection.
Parameter name: index

"amazon" wrote:

I have a following structure that I am using with array list:
Private Structure arrayliststruct
Public Name As String
Public value As String
Public type As String
End Structure

and following function to format arraylist the way I want and calling
it
from button click event:
Private Function formatarray(ByVal inarray As ArrayList, _
ByVal inName As String, _
ByVal initem As String, _
ByVal initemtype As String)

Dim arrayparam As arrayliststruct

arrayparam.Name = inName
arrayparam.value = initem
arrayparam.type = initemtype
inarray.Add(arrayparam)

Return inarray

End Function

I have follwoing code in button click event

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

Dim inarray As New ArrayList
inarray = formatarray(inarray, "Email", "my*****@email.com", "String")
inarray = formatarray(inarray, "Name", "My Name", "String")

' then I want to pass this code to web serivce that accepts arrary
list
Dim postEv As New testev.wsTEST
postEv.Credentials = Net.CredentialCache.DefaultCredentials
postEv.PreAuthenticate = True
postEv.PostExtEvent("Test", "Source", inarray(2))

End Sub

I don't know how to pass arraylist to a webservice.
please help:




Nov 7 '06 #6

P: n/a
Hi Joseph,

Thanks Again..

That only works if I move my function from webservice to local program...
I I do the same with webservice
Value of type 'System.Collections.ArrayList' cannot be converted to
'1-dimensional array of Object'
I donot understand why webservice is not expecting arraylist but the
OBJECT...

PostExtEvent(EventName as string, ExternalSource as string, inparam() as
OBJECT

event if I declared as an arraylist
"Joseph Byrns" wrote:
You should just be calling it like:

postEv.PostExtEvent("Test", "Source", inarray)

without the brackets or index, does it still not work then?

"amazon" <am****@discussions.microsoft.comwrote in message
news:3D**********************************@microsof t.com...
Thnaks Joseph

Thanks for reply..

I changed the function and declared as
Private Function formatarray(ByVal inarray As ArrayList, _
ByVal inName As String, _
ByVal initem As String, _
ByVal initemtype As String) As
ArrayList

Stil the same problem..

my web service is

Public Sub PostExtEvent(ByVal EventName As String, ByVal ExternalSource As
String, ByVal inparam As ArrayList)

Thanks

"JosephByrns" wrote:
The function:
Private Function formatarray(ByVal inarray As ArrayList, _
ByVal inName As String, _
ByVal initem As String, _
ByVal initemtype As String)

Isn't declared as anything, presumably you want:

Private Function formatarray(ByVal inarray As ArrayList, _
ByVal inName As String, _
ByVal initem As String, _
ByVal initemtype As String) As
ArrayList

Don't know if that is a typo or if it will fix your problem. If it does
not
fix the problem you might like to post the declaration for the webservice
function also.

"amazon" <am****@discussions.microsoft.comwrote in message
news:5E**********************************@microsof t.com...
I don't want to pass arralylist index with the arrary list and I am
getting
follwoing errors
1if passed without index
"number of indices is less than the number of dimensions"

2if passed with index
Index was out of range. Must be non-negative and less than the size of
the
collection.
Parameter name: index

"amazon" wrote:

I have a following structure that I am using with array list:
Private Structure arrayliststruct
Public Name As String
Public value As String
Public type As String
End Structure

and following function to format arraylist the way I want and calling
it
from button click event:
Private Function formatarray(ByVal inarray As ArrayList, _
ByVal inName As String, _
ByVal initem As String, _
ByVal initemtype As String)

Dim arrayparam As arrayliststruct

arrayparam.Name = inName
arrayparam.value = initem
arrayparam.type = initemtype
inarray.Add(arrayparam)

Return inarray

End Function

I have follwoing code in button click event

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

Dim inarray As New ArrayList
inarray = formatarray(inarray, "Email", "my*****@email.com", "String")
inarray = formatarray(inarray, "Name", "My Name", "String")

' then I want to pass this code to web serivce that accepts arrary
list
Dim postEv As New testev.wsTEST
postEv.Credentials = Net.CredentialCache.DefaultCredentials
postEv.PreAuthenticate = True
postEv.PostExtEvent("Test", "Source", inarray(2))

End Sub

I don't know how to pass arraylist to a webservice.
please help:




Nov 7 '06 #7

P: n/a
Unfortunately I don't know what is causing your difficulties. Included
below is an example I have working here (excluding all the auto generated
stuff).

Note that in your example you have the arrayliststruct declared in the aspx
part of the application, you really need to declare in the webservice part.

This part is the Webservice:

Imports System.Web.Services
Imports System.Xml.Serialization

Public Class myService
Inherits System.Web.Services.WebService
<WebMethod(), XmlInclude(GetType(arrayliststruct))_
Public Sub PostExtEvent(ByVal EventName As String, ByVal ExternalSource As
String, ByVal inparam As Object())
For Each obj As Object In inparam
Dim als As arrayliststruct = CType(obj, arrayliststruct)
Dim n As String = als.Name
Dim v As String = als.value
Dim t As String = als.type
Next
End Sub

Public Structure arrayliststruct
Public Name As String
Public value As String
Public type As String
End Structure

End Class

And this part is the web form part of the code:

Public Class WebForm1
Inherits System.Web.UI.Page

Private Function formatarray(ByVal inarray As ArrayList, _
ByVal inName As String, _
ByVal initem As String, _

ByVal initemtype As String) As ArrayList

Dim arrayparam As New myExampleService.arrayliststruct
arrayparam.Name = inName
arrayparam.value = initem
arrayparam.type = initemtype
inarray.Add(arrayparam)

Return inarray
End Function

Protected Sub btnSubmit_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles btnSubmit.Click
Dim inarray As New ArrayList
inarray = formatarray(inarray, "Email", "my*****@email.com", "String")
inarray = formatarray(inarray, "Name", "My Name", "String")

Dim ws As New myExampleService.myService
ws.PostExtEvent("Test", "Source", inarray.ToArray)
End Sub

End Class
Nov 8 '06 #8

P: n/a
Thanks Joseph,

Thant is excellent suggession and I am working on that...
However, I get follwoing error when trying to pass object to web service..

There was an error generating the XML document.
"The type System.Object[] may not be used in this context."

Thank you.
"JosephByrns" wrote:
Unfortunately I don't know what is causing your difficulties. Included
below is an example I have working here (excluding all the auto generated
stuff).

Note that in your example you have the arrayliststruct declared in the aspx
part of the application, you really need to declare in the webservice part.

This part is the Webservice:

Imports System.Web.Services
Imports System.Xml.Serialization

Public Class myService
Inherits System.Web.Services.WebService
<WebMethod(), XmlInclude(GetType(arrayliststruct))_
Public Sub PostExtEvent(ByVal EventName As String, ByVal ExternalSource As
String, ByVal inparam As Object())
For Each obj As Object In inparam
Dim als As arrayliststruct = CType(obj, arrayliststruct)
Dim n As String = als.Name
Dim v As String = als.value
Dim t As String = als.type
Next
End Sub

Public Structure arrayliststruct
Public Name As String
Public value As String
Public type As String
End Structure

End Class

And this part is the web form part of the code:

Public Class WebForm1
Inherits System.Web.UI.Page

Private Function formatarray(ByVal inarray As ArrayList, _
ByVal inName As String, _
ByVal initem As String, _

ByVal initemtype As String) As ArrayList

Dim arrayparam As New myExampleService.arrayliststruct
arrayparam.Name = inName
arrayparam.value = initem
arrayparam.type = initemtype
inarray.Add(arrayparam)

Return inarray
End Function

Protected Sub btnSubmit_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles btnSubmit.Click
Dim inarray As New ArrayList
inarray = formatarray(inarray, "Email", "my*****@email.com", "String")
inarray = formatarray(inarray, "Name", "My Name", "String")

Dim ws As New myExampleService.myService
ws.PostExtEvent("Test", "Source", inarray.ToArray)
End Sub

End Class
Nov 8 '06 #9

This discussion thread is closed

Replies have been disabled for this discussion.