views:

243

answers:

2

I have a web service that when invoked, returns a Result object that contains a List polymorphically. However, when I add a reference in my client application, the public field becomes an array of Country in the client application. How do I change the field in the client application to List?

public Result GetCountryList()
{
    List<Country> countries = GrabCountryList();
    Result result = new Result();
    result.theResult = countries;
}

and this is the public property

public object theResult
{
     get {return _theResult; }
     set {_theResult = value;}
}


Accepted answer from Mehmet Aras:

Right click on the service reference, and select "Configure Reference". Under Collection type, select System.Collection.Generic.List. Update the service reference, and it should be good to go.

Thanks to Matt Hamilton for the suggestion to create a new list from the array.

+6  A: 

I believe you'll have to reconstruct the list yourself. Web services are supposed to be language agnostic, and since List<T> is part of the .NET framework, it can't be part of the serialized return values.

Reconstructing the list is as simple as:

var countries = new List<Country>(result.theResult);
Matt Hamilton
+7  A: 

If you're using VS2008, there is an advanced button on the service reference settings form that allows you control the client proxy generation. There you can select the collection type and list is among them.

Mehmet Aras