all groups > dotnet web services > october 2007 >
You're in the

dotnet web services

group:

Pass class object to web service



Pass class object to web service TTK
10/22/2007 11:05:03 AM
dotnet web services: Hello, I have been researching this for a long time. I am trying to find out
how I can pass an object to a web service. I need details on the code in
vb.net if possible. I would like to have the client to send an object
"Order" to a web service.

Public Class Order
Public OrderID As New ArrayList ' array list of integers
Public OrderXML As New ArrayList 'array list of string
Public LineNumber As New ArrayList 'array list of integer
Public Attachment As New ArrayList ' array list of byte
End Class

the client will populate the array lists and pass it to the web service. I
am getting error
<Error 1 Value of type 'ClassLibrary1.Module1.Order' cannot be converted to
'ClassLibrary1.Webservice.Order'.>

the question is :
1. where do I define this class. in the web service or the client.
2. can somebody gives a full example how the code should look like on the
client and the web service in VB.NET. I hear XML seriallized/deserialized,
SOAP RPC, XMLInclude..... I am getting lost. Any help will be very appreciated
Re: Pass class object to web service TTK
10/22/2007 7:49:01 PM
Thanks John for the response. I have tried everything and I am getting errors.
First, I define the class in the webservice "localhost.orderWS".
======================================
Public Class Order
Public OrderID As New ArrayList ' array list of integers
Public OrderXML As New ArrayList 'array list of string
Public LineNumber As New ArrayList 'array list of integer
Public Attachment As New ArrayList ' array list of byte
End Class
======================================

Second, I have the class as a parameter in the webmethod function:
======================================
<System.Web.Services.WebMethod()> _
Public Function getMessage(ByVal clsOrder As Order)
'code to verify the values are passed
MsgBox("Oder ID: " + clsOrder.orderID(0) )
......
......
======================================

Third, on the client side, I have the following:
======================================
dim ws as new localhost.orderWS
dim clsOrder as new localhost.order

clsOrder.orderid.insert(0,123)
clsOrder.orderid.insert(1,23455)
clsOrder.orderxml.insert(0,"<order><ordernumber>123</ordernumber></order>")
clsOrder.orderxml.insert(1,"<order><ordernumber>23455</ordernumber></order>")
.......
......
ws.getMessage(clsOrder)
========================================
I have looked at tons of books and online pages but I am not able to resolve
the error. It is complaining that "'Insert' is not a member of 'System.Array'.

Do I need to imports anything special. do I need to use xmlinclude or
soaprpc or soapinclude in the web service. This is crazy....

[quoted text, click to view]
Re: Pass class object to web service John Saunders [MVP]
10/22/2007 8:25:02 PM
[quoted text, click to view]

If you don't define it on the server, then how would the server know what to
do with it? Define it on the server, and have the client use the proxy
version of it.
--
--------------------------------------------------------------------------------
John Saunders | MVP - Windows Server System - Connected System Developer

Re: Pass class object to web service Spam Catcher
10/23/2007 2:28:21 AM
=?Utf-8?B?VFRL?= <TTK@discussions.microsoft.com> wrote in news:0C20A41F-
C255-493D-A284-D96875C9034C@microsoft.com:

[quoted text, click to view]

You need to define the Order object on the server side. Once you define a
function which accepts an oder parameter (or returns one) the client
generate proxy will have a version of it.

If your server need to handle unknown data formats/objects... then you can
RE: Pass class object to web service TTK
10/24/2007 7:41:01 AM
It took me sometime to figure out what my issue is but I am still looking for
help. The issue is not passing an object to a web service because I was able
to do that easily when the object contains simple datatypes. The issue is to
pass the arraylist to the web service. It is not allowing me to do that. I
have the arraylist as an input parameter in the webmethod function. Then I
instantiate the variable on the client side and populate the arraylist. When
I call the webmethod function and try to pass the arraylist to it, I get
<Error 'System.Collections.ArrayList' cannot be converted to '1-dimensional
array of Object'.> Please give me any help.... this has been taking more than
60 hours of research and trying different things. thanks


[quoted text, click to view]
RE: Pass class object to web service TTK
10/24/2007 7:51:03 AM
oh my God, I was able to resolve it my self finally. All what I had to do is
add to the arraylist variable "myarraylist.toarray()" when I pass it to the
web service method. Wow. Really wow. That solved it. I think it is misleading
that they are using .toarray() to convert it. But hey... it works :-)

[quoted text, click to view]
RE: Pass class object to web service Spam Catcher
10/24/2007 2:48:32 PM
=?Utf-8?B?VFRL?= <TTK@discussions.microsoft.com> wrote in
news:A9DB8E10-616B-472F-BFAF-DAD28C02C398@microsoft.com:

[quoted text, click to view]

AFAIK, you can't pass an arraylist in .NET 2.0 web service. You can however
pass a standard array.

So change your arraylist data type to an array.


(You can use an array on the server side, but when you return the data to
AddThis Social Bookmark Button