【发布时间】:2013-08-21 07:48:40
【问题描述】:
我目前正在将 HttpListener 应用程序转换为 WCF Web 服务。 Web 服务将由运行 .NETCF 2.0 的 Windows CE 5.0 客户端使用。我已经通过 Web 参考(不是服务参考)让这个工作正常。值得一提的是,我无法将框架版本从 2.0 升级到 3.0 或 3.5。
我遇到的问题是我有多个包含 List 属性的类(如下所示)
[Serializable]
[XmlRoot]
public class Products
{
public Products()
{
Items = new List<Product>();
Errors = new List<Error>();
}
[XmlElement]
public List<Product> Items
{ get; set; }
[XmlElement]
public List<Error> Errors
{ get; set; }
[XmlElement]
public long DeviceId
{ get; set; }
[XmlElement]
public User UserId
{ get; set; }
[XmlElement]
public long UserColour
{ get; set; }
}
当这个属性通过 Web Reference 传递时,List 变成了一个数组(如下所示)
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(Namespace="http://server-path/Service.svc")]
public partial class Products {
/// <remarks/>
[System.Xml.Serialization.XmlElementAttribute("Items")]
public Product[] Items;
/// <remarks/>
[System.Xml.Serialization.XmlElementAttribute("Errors")]
public Error[] Errors;
/// <remarks/>
public long DeviceId;
/// <remarks/>
public User UserId;
/// <remarks/>
public long UserColour;
}
我知道使用服务引用可以更改通过服务传递的集合的集合类型,但是我不知道如何使用 Web 引用来实现这一点。
我见过很多其他类似的问题,例如this 和this,但通常的解决方案是使用服务参考,但我无法使用。
有没有一种方法可以在 Web 服务中维护集合类型,或者我可以在客户端实现一种解决方法?
谢谢, 哈登
【问题讨论】:
标签: c# wcf web-services