I have two simple classes: an Order object, which contains a list of OrderLine objects:
public class Order
{
public string OrderNo { get; set; }
public string CustomerName { get; set; }
public List<OrderLine> Lines { get; set; }
}
public class OrderLine
{
public string ItemNo { get; set; }
public int Qty { get; set; }
public decimal Price { get; set; }
}
[WebMethod]
public Order GetOrder(string orderNo)
{
return null;
}
[WebMethod]
public List<Order> GetOrderList(string orderNo)
{
return null;
}
The problem is that the details (properties) of the OrderLine objects in the Orders are not rendered by the second WebMethod (it works fine with the first WebMethod):
The first WebMethod (returning an Order), renders this XML (properly, with ItemNo, Qty & Price for each OrderLine):
<GetOrderResult>
<OrderNo>string</OrderNo>
<CustomerName>string</CustomerName>
<Lines>
<OrderLine>
<ItemNo>string</ItemNo>
<Qty>int</Qty>
<Price>decimal</Price>
</OrderLine>
<OrderLine>
<ItemNo>string</ItemNo>
<Qty>int</Qty>
<Price>decimal</Price>
</OrderLine>
</Lines>
</GetOrderResult>
The second WebMethod (returning a List), renders this XML (note that the OrderLines are no longer rendered with details):
<GetOrderListResult>
<Order>
<OrderNo>string</OrderNo>
<CustomerName>string</CustomerName>
<Lines>
<OrderLine xsi:nil="true" />
<OrderLine xsi:nil="true" />
</Lines>
</Order>
<Order>
<OrderNo>string</OrderNo>
<CustomerName>string</CustomerName>
<Lines>
<OrderLine xsi:nil="true" />
<OrderLine xsi:nil="true" />
</Lines>
</Order>
</GetOrderListResult>
How can I get the OrderLines to render with details instead of as xsi:nil="true"??
Thanks.
Thanks for the reply, but that does not help. The code I posted is simplified as much as possible; the real code of course instantiates the list, etc., but still has the same issue. But I still tried your suggestion in the sample:
public class Order
{
public string OrderNo { get; set; }
public string CustomerName { get; set; }
public List<OrderLine> Lines { get; set; }
public Order()
{
Lines = new List<OrderLine>();
Lines.Add(new OrderLine());
Lines.Add(new OrderLine());
}
}
The WebMethod still returns:
<GetOrderListResult>
<Order>
<OrderNo>string</OrderNo>
<CustomerName>string</CustomerName>
<Lines>
<OrderLine xsi:nil="true" />
<OrderLine xsi:nil="true" />
</Lines>
</Order>
<Order>
<OrderNo>string</OrderNo>
<CustomerName>string</CustomerName>
<Lines>
<OrderLine xsi:nil="true" />
<OrderLine xsi:nil="true" />
</Lines>
</Order>
</GetOrderListResult>