Passing an object to web service - best practice

Last post 11-09-2009 7:28 AM by TATWORTH. 5 replies.

Sort Posts:

  • Passing an object to web service - best practice

    11-01-2009, 1:00 PM
    • Member
      2 point Member
    • r12345
    • Member since 12-04-2008, 8:16 AM
    • Posts 66

    Hi,

    I would like to create a webservice for processing an order and I would like to know what would be the best practice in passing an Order object through my web method.

    Currently, I created a class called Order which consist of all of the variable I would need to pass.

    Is it better to pass this object as an XML object? IF so, why and how?

    This is what I currently have:

    [Webmethod]

    public void createOrder(Order order)

    {

    }

     

    Entity: order.cs

    private string _orderNumber;

    public string OrderNumber

    { get; set; }

    etc.

     

    Thanks in advance for your response.  

  • Re: Passing an object to web service - best practice

    11-01-2009, 2:54 PM

    Well, keep it as is, because if you want to send an xml object, then you are going to need write more code in UI to convert the object to xml.

    Passing Object is a good idea.


    Plz remember to click "Mark as Answer" if this helped you.

    Abdulla AbdelHaq    MCTS, MCPD

    - My Articles on ASP Alliance
    - My Weblogs
    - My Sessions on JorDev User Group

    "Experience is simply the name we give our mistakes"
  • Re: Passing an object to web service - best practice

    11-02-2009, 2:18 AM
    • Member
      2 point Member
    • r12345
    • Member since 12-04-2008, 8:16 AM
    • Posts 66

    Thanks for your response. But, what is the pros and cons between an object and xml. Which one is better and why?

    Abdulla.AbdelHaq:
    you are going to need write more code in UI to convert the object to xml

     

    Can you give me sample code of how to convert an object to an xml?

     

    Thanks in advance.

  • Re: Passing an object to web service - best practice

    11-02-2009, 12:47 PM

    Well, it depend on your current case.

    are you passing a herirarcy data ? if yes then XML will be a good choice. but if you are passing a single object, then passing a object will be a good idea than passing an xml.

    at the end, webservice is converting your object into XML (serialization) behind the scenes.

     

    Plz remember to click "Mark as Answer" if this helped you.

    Abdulla AbdelHaq    MCTS, MCPD

    - My Articles on ASP Alliance
    - My Weblogs
    - My Sessions on JorDev User Group

    "Experience is simply the name we give our mistakes"
  • Re: Passing an object to web service - best practice

    11-06-2009, 5:16 PM
    • Member
      2 point Member
    • r12345
    • Member since 12-04-2008, 8:16 AM
    • Posts 66

    Do you have an example or pointer to how passing an xml into webservice? Thanks. 

  • Re: Passing an object to web service - best practice

    11-09-2009, 7:28 AM
    • All-Star
      63,220 point All-Star
    • TATWORTH
    • Member since 02-04-2003, 8:34 AM
    • England
    • Posts 12,352
    • TrustedFriends-MVPs

    Is your object marked with a serializable attribute?

    Don't forget to click "Mark as Answer" on the post that helped you.
    This credits that member, earns you a point and marks your thread as Resolved so we will all know you have been helped.
Page 1 of 1 (6 items)