passing collection object to web service in .NET

  • Thread starter Thread starter vbvjain
  • Start date Start date
V

vbvjain

I am developing an applocation which reads mails in outlook inbo
alongwith attachments and all these informmation is stored in
collection which i need to pass it to a web service, which will perfor
certain operations on that collection and then return that modifie
collection to the client.
but when i am trying to pass a simple collection of strings to my we
service it gives me an error "You must implement Add(System.Object) a
it inherits from IColletion".
Can someone tell me the exact way as to how i can pass collection t
and from a web service in VB.NET

Thanks in advanc


-
vbvjai
 
I prefer using arrays and its collection-like counterpart, the
arraylist. When using an arraylist, you have the add and remove and
removeat methods, but the key for transferring between two objects is
the .ToArray and the .AddRange methods. The former converts the
arraylist into a literal array of objects. You can do it with Option
strict on too, but it's a bit more verbose:

dim x as dtoObject ' For illustration only
dim al as arraylist
dim obj as new webservice

obj.callingMethod(ctype(al.toarray(gettype(dtoObject)),dtoObject())

So what you're saying is convert the arraylist to array of type
dtoObject, but ToArray returns an object (subtype dtoObject()), so you
have to strong type it back to dtoObject()

Then when you receive it as an input parameter, its as simple as

public sub InMethod(dto() as dtoObject)
al.addrange(dto)
end sub

Hope that helps. It might not be the answer you wanted, but it is a
very easy technique that you should try. If you have a specific need to
use a Collection type, let me know and I'll clarify my answer.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top