XML Serialisation problem - sending a business object over a webservice

Discussion in 'ASP .Net' started by Nick Gilbert, May 25, 2005.

  1. Nick Gilbert

    Nick Gilbert Guest

    Hi,

    I'm developing a webservice that will accept an Order and forward it to
    a backend system, but I'm having a problem with transferring my "Order"
    class over a webservice.

    When I try and call the webservice and pass it an Order, I get the
    following error message:

    The type Wright.BusinessLogicLayer.OrderLine was not expected. Use the
    XmlInclude or SoapInclude attribute to specify types that are not known
    statically.

    Source Error:

    Line 55: public string EchoOrder(Order order) {
    Line 56: object[] results = this.Invoke("EchoOrder", new
    object[] {
    Line 57: order});
    Line 58: return ((string)(results[0]));

    My Order class currently contains a single property, which is just an
    ArrayList of OrderLine objects.

    I've tried adding the SoapAttribute as the error message suggests but it
    seems to have no effect:

    [WebMethod]
    [SoapInclude(typeof(OrderLine))]
    public string EchoOrder(Order order) {
    return order.ToString();
    }

    Any ideas what am I doing wrong?

    Thanks!

    Nick...
    Nick Gilbert, May 25, 2005
    #1
    1. Advertising

  2. Nick Gilbert

    Nick Gilbert Guest

    Re: XML Serialisation problem - sending a business object over awebservice

    The odd thing is, if I change my class so that it has a single OrderLine
    object instead of an arraylist of them:

    public OrderLine Item {
    get { return item; }
    set { item = value; }
    }

    as opposed to:

    public ArrayList OrderItems {
    get { return orderItems; }
    set { orderItems = value; }
    }

    Then it works fine. So it's obviously having trouble serializing the
    ArrayList of OrderItems.

    I don't know how to fix this and I can't proceed with my project until
    I've got this working! Needless to say - I'm getting very stressed and
    worried!

    Nick...
    Nick Gilbert, May 25, 2005
    #2
    1. Advertising

  3. Re: XML Serialisation problem - sending a business object over a w

    Try decorating the OrderItems property with the XmlArray attribute found in
    System.Xml.Serialization


    "Nick Gilbert" wrote:

    > The odd thing is, if I change my class so that it has a single OrderLine
    > object instead of an arraylist of them:
    >
    > public OrderLine Item {
    > get { return item; }
    > set { item = value; }
    > }
    >
    > as opposed to:
    >
    > public ArrayList OrderItems {
    > get { return orderItems; }
    > set { orderItems = value; }
    > }
    >
    > Then it works fine. So it's obviously having trouble serializing the
    > ArrayList of OrderItems.
    >
    > I don't know how to fix this and I can't proceed with my project until
    > I've got this working! Needless to say - I'm getting very stressed and
    > worried!
    >
    > Nick...
    >
    =?Utf-8?B?SmFtZXM=?=, May 25, 2005
    #3
  4. Nick Gilbert

    Guest

    I believe you need to put the SoapInclude attribute on your Order class
    (the class that will contain the OrderLine class). That way when it
    goes to serialize the Order class it will also know to pull in the
    OrderLine class.

    jeffpriz
    , May 25, 2005
    #4
  5. Nick Gilbert

    Guest

    bah never mind you had it correct.. I was used to using a different
    serializtion attribute and assumed they worked similiarly.. sry
    , May 25, 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. ickz
    Replies:
    1
    Views:
    335
    Esmond Pitt
    May 13, 2005
  2. Chris Meek

    Complex object Serialisation

    Chris Meek, Jan 8, 2007, in forum: ASP .Net
    Replies:
    0
    Views:
    290
    Chris Meek
    Jan 8, 2007
  3. Rotsey
    Replies:
    3
    Views:
    335
    John Saunders [MVP]
    Aug 2, 2007
  4. feng

    object serialisation

    feng, Nov 19, 2010, in forum: Java
    Replies:
    11
    Views:
    587
  5. Une bévue

    yaml object de-serialisation

    Une bévue, Feb 9, 2006, in forum: Ruby
    Replies:
    9
    Views:
    122
    David Vallner
    Feb 10, 2006
Loading...

Share This Page