Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Web Services > passing custom classes or stucture as arguments

Reply
Thread Tools

passing custom classes or stucture as arguments

 
 
Joe Abou Jaoude
Guest
Posts: n/a
 
      12-10-2005


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



*** Sent via Developersdex http://www.developersdex.com ***
 
Reply With Quote
 
 
 
 
Paul Gielens
Guest
Posts: n/a
 
      12-10-2005

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/eaaCatal...ferObject.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/Resource...t/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/
###

"Joe Abou Jaoude" <(E-Mail Removed)> wrote in message
news:OQkQ5eY$(E-Mail Removed)...
>
>
> 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
>
>
>
> *** Sent via Developersdex http://www.developersdex.com ***
>




 
Reply With Quote
 
 
 
 
Joe Abou Jaoude
Guest
Posts: n/a
 
      12-11-2005


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


*** Sent via Developersdex http://www.developersdex.com ***
 
Reply With Quote
 
Mork
Guest
Posts: n/a
 
      12-11-2005
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

 
Reply With Quote
 
m.posseth
Guest
Posts: n/a
 
      12-14-2005

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]


"Mork" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) oups.com...
> 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
>



 
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
data stucture using c enrique C Programming 7 09-06-2006 09:15 PM
Passing Classes as Arguments to Functions of Other Classes crouse@physics.wm.edu Java 7 08-12-2006 02:08 AM
"Invalid FORMATETC stucture" when dragging a custom Gridview onto Dave ASP .Net Building Controls 4 07-20-2006 07:07 PM
Size of Stucture without sizeof() Robotnik C Programming 55 12-07-2005 03:05 AM
Table stucture changing when panel is displayed Pavan ASP .Net 3 09-16-2005 11:29 PM



Advertisments