XML Serialisation problem - sending a business object over a webservice

N

Nick Gilbert

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...
 
N

Nick Gilbert

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...
 
G

Guest

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

jeffpriz

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
 
J

jeffpriz

bah never mind you had it correct.. I was used to using a different
serializtion attribute and assumed they worked similiarly.. sry
 

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,995
Messages
2,570,236
Members
46,822
Latest member
israfaceZa

Latest Threads

Top