passing custom classes or stucture as arguments

Discussion in 'ASP .Net Web Services' started by Joe Abou Jaoude, Dec 10, 2005.

  1. 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 ***
    Joe Abou Jaoude, Dec 10, 2005
    #1
    1. Advertising

  2. Joe Abou Jaoude

    Paul Gielens Guest

    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/
    ###

    "Joe Abou Jaoude" <> wrote in message
    news:OQkQ5eY$...
    >
    >
    > 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 ***
    >
    Paul Gielens, Dec 10, 2005
    #2
    1. Advertising

  3. 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 ***
    Joe Abou Jaoude, Dec 11, 2005
    #3
  4. Joe Abou Jaoude

    Mork Guest

    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
    Mork, Dec 11, 2005
    #4
  5. Joe Abou Jaoude

    m.posseth Guest

    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" <> wrote in message
    news:...
    > 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.posseth, Dec 14, 2005
    #5
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Pavan
    Replies:
    3
    Views:
    636
    Pavan
    Sep 17, 2005
  2. Replies:
    7
    Views:
    545
    Alex Hunsley
    Aug 12, 2006
  3. Robotnik

    Size of Stucture without sizeof()

    Robotnik, Dec 1, 2005, in forum: C Programming
    Replies:
    55
    Views:
    983
    Keith Thompson
    Dec 7, 2005
  4. enrique

    data stucture using c

    enrique, Aug 26, 2006, in forum: C Programming
    Replies:
    7
    Views:
    321
    Smurff
    Sep 6, 2006
  5. Dave
    Replies:
    4
    Views:
    116
    Alessandro Zifiglio
    Jul 20, 2006
Loading...

Share This Page