WCF:泛型列表序列化数组 [英] WCF: generic list serialized to array

查看:153
本文介绍了WCF:泛型列表序列化数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我与WCF的工作和我的服务返回包含泛型列表类型。 WCF目前正在通过线路将这些到阵列。有没有一种方法,我配置WCF他们事后转换回列表?我知道有办法通过单击高级当你添加一个服务引用,但我正在寻找在配置文件中或类似的解决方案。

So I am working with WCF and my services return types that contain generic lists. WCF is currently converting these to arrays over the wire. Is there a way I configure WCF to convert them back to lists afterwards? I know there is a way by clicking advanced when you add a service reference but I am looking for a solution in configuration files or something similar.

[DataContract(IsReference = true)]
public class SampleObject
{
  [DataMember]
  public long ID { get; private set; }

  [DataMember]
  public ICollection<AnotherObject> Objects { get; set; }
}

这是非常奇怪的,也因为一个服务返回它作为一个列表和其他作为一个数组,我pretty确保它们是相同的配置。

It is very odd, also, because one service returns it as a list and the other as an array and I am pretty sure they are configured identically.

推荐答案

我找到了解决办法,这是更简单,工作不够好,对我来说,虽然它可能不为别人打工。我只是使用的ICollection(IList中也产生这样的结果)可以列出切换。这之后的正常工作。

I found a solution that was much simpler and worked well enough for me, although it might not work for others. I simply switched from using ICollection (IList also produces this result) to List. It worked fine after that.

从<一个解决方案href=\"http://stackoverflow.com/questions/2562088/wcf-serializing-and-deserializing-generic-collections\">Here.

我也发现一个可能的配置解决方案这里接近底部

<CollectionMappings>
    <CollectionMapping TypeName="ChangeTracker.ChangeTrackingCollection'1" Category="List" />
</CollectionMappings>

这篇关于WCF:泛型列表序列化数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆