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

|▌冷眼眸甩不掉的悲伤 提交于 2019-11-30 12:20:26

When you add reference to wcf service you need to change Collection Type to Generic List:

You can also update this settings just select service reference inside your solution, make right mouse click and select "Configure Service Reference..."

What did it for me was:

  1. install all updates to Visual Studio 2013
  2. uncheck "reuse types in referenced assemblies"

I had the same problem with VS2010. After hours of trying and testing I think, this is a bug of code generation. I was able to reproduce it. Here is code on server side, which has impact on behavior of Visual Studio code generation. The commented line generated this problem in my case. When this member was not nullable, then Visual studio generated Array collections instead List<>.

[DataContract]
public enum DocumentAttachmentSourceType
{
    [EnumMember]
    ServiceMission                              
}

[MessageContract]
public class DocumentUploadRequest : IDisposable
{
    [MessageHeader]
    public long NodeId { get; set; }

    [MessageHeader]
    public DocumentAttachmentSourceType? AttachmentSource { get; set; } //This works
    //public DocumentAttachmentSourceType  AttachmentSource { get; set; }   //This not works !!!!!!!

    [MessageBodyMember]
    public System.IO.Stream Stream { get; set; }


    public void Dispose()
    {
        if (Stream != null)
        {
            Stream.Close();
            Stream = null;
        }
    } 

}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!