locked
Serialization IEnumerable in WCF RRS feed

  • Question

  • User-1350042179 posted

    Hi

    I Knew that when I serialize IEnumerable  in wcf is not posible since IEnumerable can't be serialized since it is a interface., so many years ago I obtained the error:

    Cannot serialize member :

    https://stackoverflow.com/questions/15925060/how-to-use-datamember-for-ienumerablestring-for-property-in-wcf

    Now, the wcf returns an "ienumerable" and it doesn't return error..

    My method is: ver()

    public CompositeType1 ver()
         {
     
             return new CompositeType1 { ver = ver1() };
     
         }
     
         public IEnumerable<int> ver1()
         {
              var x = new List<int>()
             {
                 1,
                 2,
                 3
             };
     
             return x;
         }

    And it returns an ienumerable without errors... I suppose that Microsoft fixed after VS 2013.

    Wednesday, November 22, 2017 9:00 PM

Answers

  • User1168443798 posted

    Hi neoaguil,<o:p></o:p>

    >> I supose that I won't have problems if I use ienumerable in WCF since ienumerable<> and a list<> are converted to the same in case of xml or json<o:p></o:p>

    Yes, as you have found, and I also make a test with IEnumerable, it works. You could work with WCF without worrying about IEnumerable.<o:p></o:p>

    I assume it is related with .NET Framework and WCF Service version.<o:p></o:p>

    Best Regards,<o:p></o:p>

    Edward<o:p></o:p>

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, November 24, 2017 6:22 AM

All replies

  • User1120430333 posted

    And it returns an ienumerable without errors... I suppose that Microsoft fixed after VS 2013.

    https://docs.microsoft.com/en-us/dotnet/framework/wcf/feature-details/collection-types-in-data-contracts

    <copied>

    Collection interface types (IEnumerable, IDictionary, generic IDictionary<TKey,TValue>, or interfaces derived from these interfaces) are also considered as having collection data contracts, equivalent to collection data contracts for actual collection types. Thus, it is possible to declare the type being serialized as a collection interface type and the results are the same as if an actual collection type had been used. For example, the following data contracts are equivalent.

    <end>

    Wednesday, November 22, 2017 10:46 PM
  • User-1350042179 posted

    Hi

    In that case I supose that I won't have problems if I use ienumerable in WCF since ienumerable<> and a list<> are converted to the same in case of xml or json.

    But I don't understand why some people got an error some years ago: And it returns an ienumerable without errors... I suppose that Microsoft fixed after VS 2013

     

    Friday, November 24, 2017 1:25 AM
  • User1168443798 posted

    Hi neoaguil,<o:p></o:p>

    >> I supose that I won't have problems if I use ienumerable in WCF since ienumerable<> and a list<> are converted to the same in case of xml or json<o:p></o:p>

    Yes, as you have found, and I also make a test with IEnumerable, it works. You could work with WCF without worrying about IEnumerable.<o:p></o:p>

    I assume it is related with .NET Framework and WCF Service version.<o:p></o:p>

    Best Regards,<o:p></o:p>

    Edward<o:p></o:p>

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, November 24, 2017 6:22 AM