Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
918 views
in Technique[技术] by (71.8m points)

.net - 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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...