pStan
pStan

Reputation: 1104

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.

Upvotes: 7

Views: 14926

Answers (1)

John Saunders
John Saunders

Reputation: 161773

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

enter image description here

Upvotes: 8

Related Questions