Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Returning a List of type from web service

I want to return a list of some inventory from a web service. It seems that the web service forces the the list to return as an array.

In the following 3 lines the array portion works, but I can't figure out how to cast it back to a list of type "InventoryToSync"

List<InventoryToSync> inventoryList = new List<InventoryToSync>();
Array theArray = myIcsSyncService.ReturnInventoryToSyncDictionary();
inventoryList = myIcsSyncService.ReturnInventoryToSyncDictionary().Cast<InventoryToSync>();

Here is my web method:

    [WebMethod]
    [System.Xml.Serialization.XmlInclude(typeof(InventoryToSync))]
    public List<InventoryToSync> ReturnInventoryToSyncDictionary()
    {
        Inventory inventory = new Inventory();

        return inventory.GetInventoryList();
    }

I tried to force the type with XmlInclude, but still no go.

How to I force the web service to return a list of my InventoryToSync, or how do I convert the array back to Inventory to Sync.

like image 284
pStan Avatar asked Jun 12 '13 22:06

pStan


1 Answers

In the "Add Service Reference" dialog, click "Advanced" and choose to use List<T> as the collection type.

enter image description here

like image 90
John Saunders Avatar answered Oct 05 '22 21:10

John Saunders