我正在將HttpListener應用程序轉換爲WCF Web服務。 Web服務將由運行.NETCF 2.0的Windows CE 5.0客戶端使用。我已經通過Web引用(不是服務引用)正常工作了。在這裏值得一提的是,我無法將框架版本從2.0升級到3.0或3.5。如何在Web服務中維護集合類型(使用Web引用而非服務引用)
我遇到的問題是,我有包含列表屬性(如下面的一個)
[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引用傳遞的列表成爲一個數組(如下圖所示多個類)
[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,但通常的解決方案是使用Service Reference,我無法使用它。
有沒有一種方法可以維護整個Web服務的集合類型,或者我可以實現客戶端的解決方法?
感謝, 哈登