passing custom classes or stucture as arguments

J

Joe Abou Jaoude

Is it possible to pass custom classes or stucture as arguments to a
webservice method ?

In remoting, I was able to do so by placing the custom class in a shared
dll referenced by both the client and the server.

I tried this in the web service.I created a shared dll.
my web application has a reference to the dll, my web service has a
reference to the same dll.But I can't call the webmethod. For the
compiler they are two different classes and can't convert one type to
another.

what can I do abou it ?
Regards
 
P

Paul Gielens

Hi Joe,

Web services communicate using XML/SOAP. As soon as you reference the web
service on the client a proxy is generated, the proxy class handless the
work mapping parameters to XML elements and then sending the SOAP message
over the nerwork. Your web service and clients exchange messages, not
objects!

The WSDL tool is used to generate a proxy class. I advise you to not alter
these classes. Look at the generated classes as being Data Transfer Objects
(DTO, http://www.martinfowler.com/eaaCatalog/dataTransferObject.html) and
map these against your custom entity classes compiled in your shared
assembly. An alternative is to do Contract-First development (see
http://www.thinktecture.com/Resources/Software/WSContractFirst/default.html).

You have a bit of reading-up to do regarding web services... see
Considerations for Custom Web Service Client Proxy Classes here
http://msdn2.microsoft.com/en-us/library/ms181858.aspx


Best regards,
Paul Gielens

Visit my blog @ http://weblogs.asp.net/pgielens/
###
 
J

Joe Abou Jaoude

Hi Paul,
Thx for your reply.

I m perfectly aware that web services communicate using XML/SOAP and
that a proxy class is generated when I add a web reference.

All what I wanted to do is pass some data in an object as argument to a
WebMethod. An alternative would be to pass a couple of douzen of data
type arguments instead of encapsulating the data in an object.

The problem was that the proxy class generated by the WSDL expected a
type different than the type supplied as argument.
example:
I have a service service1.asmx a webmethod Method1 (ByVal obj as
SharedCode.CustomObject).

The generated proxy would have a method that expects an object of type
Service1.CustomObject as argument (and not SharedCode.CustomObject)

So finally, the only thing that I could find (although it might not be
recommended) is to alter the proxy class so it expect the proper object.

Regards
 
M

Mork

Joe,

The Web Services tools with Visual Studio don't handle this scenario
where your client and service share the same data/message contracts
assembly. You'll need to manage the proxy class yourself. Generate it
and then delete everything exept the proxy class. Add the a using
statement for your SharedCode.

Cheers,
~Mork
 
M

m.posseth

hmmm something is wrong in this thread ......


as a few years ago i had to comunicate with a webservice made with progress
, this was about transfering orderrows to a mainframe system the other party
had already made this service
with a array of basketrow structure

this is my code

Dim fsBr As companyX.savebasket_basketRow

Dim fsBrArr(dt.Rows.Count - 1) As companyX..savebasket_basketRow

Dim icount As Integer

For Each dr In dt.Rows

fsBr = New companyX..savebasket_basketRow

fsBr.articlenum = CStr(dr.Item(0))

fsBr.artdescription = CStr(dr.Item(1))

fsBr.artgroup = CStr(dr.Item(2))

fsBr.manufacturer = CStr(dr.Item(3))

fsBr.artprice = CDec(dr.Item(4))

fsBr.artamount = CInt(dr.Item(5))

fsBrArr(icount) = fsBr

icount += 1

Next

companyX..Connect_tirep(strUsername, strPassword, sID)

companyX..savebasket(fsBrArr, sID)



as you see this works like a charm currently this webservice is ported on
there side to a Java webservice companyX.savebasket_basketRow is declared in
there wsdl ( not on my side )

my experience is that you can use structures through a webservice without
anny problems as long as these structures contain simple data types

regards

Michel Posseth [MCP]
 

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

Members online

No members online now.

Forum statistics

Threads
473,997
Messages
2,570,239
Members
46,827
Latest member
DMUK_Beginner

Latest Threads

Top