Grandizer
Grandizer

Reputation: 3025

WCF Returning Array instead of List EVEN THOUGH Collection Type == Generic.List

I have project that is a WCF service (.svc) that looks like the following:

[ServiceContract]
public interface IAdminQueries
{

    [OperationContract]
    List<Color> GetColors();

    [OperationContract]
    List<PhoneType> GetPhoneTypes();

    ...

I have another project that is a Web Application. I add a Service Reference to the above Service. Click the Advanced button and select Generic.List from the Collection Type. All seems as it should be.

I then build and get errors with the code below:

    AdminQueriesClient db = new AdminQueriesClient();
    List<Color> s = db.GetColors();

Here is the error:

    Cannot implicitly convert type 'DogLicenseBO.DogLicenseServiceReference.Color[]' to 'System.Collections.Generic.List<DogLicenseBO.DogLicenseServiceReference.Color>'

Is something blocking or overriding the normal serialization/deserialization process?

EDIT I have it working again. However, I think I need what I took out though.

The Fix This all started because I have to convert a VS 2012 project to VS 2010. Lots a great features I was using but have to downgrade. Anyway, one of the References in VS 2012 is Newtonsoft.Json. I am using that in a couple of places. When I took that out in VS 2010 and rebuilt, everything worked. Now I need more testing to see what I can use for the Json serialization instead of Newtonsoft.

Any suggestions?

Upvotes: 3

Views: 2049

Answers (2)

Grandizer
Grandizer

Reputation: 3025

The Answer is up in my original post after the EDIT called Fix. But I may as well post it here too.

This all started because I have to convert a VS 2012 project to VS 2010. Lots a great features I was using but have to downgrade. Anyway, one of the References in VS 2012 is Newtonsoft.Json. I am using that in a couple of places. When I took that out in VS 2010 and rebuilt, everything worked. Now I need more testing to see what I can use for the Json serialization instead of Newtonsoft.

Upvotes: 1

Quintin Robinson
Quintin Robinson

Reputation: 82335

In the client where you have added the service reference, right click on the service reference and select "Configure Service Reference", under the section for data type it should list "System.Array" for Collection types (because that is the default emitted for non-.NET client compatibility). In this area you can change it to emit a generic list by default instead of an array.

Upvotes: 0

Related Questions