0

I am currently converting a HttpListener application to a WCF web service. The web service will be consumed by a Windows CE 5.0 client running .NETCF 2.0. I have this working fine already via a Web Reference (not a Service Reference). And it may be worth mentioning here that i am unable to upgrade the framework version from 2.0 to 3.0 or 3.5.

The issue i am having is that i have multiple classes that contain List properties (like the one below)

[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; }
}

Which when this property is passed through the Web Reference the List becomes an Array (shown below)

[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;
}

I am aware that using Service References it is possible to change the collection type of collections passed through the service, however i do not know how i can achieve this using a Web Reference.

I have seen many other similar questions, like this and this, but the usual solution is to use a Service Reference, which i am unable to use.

Is there a way i can maintain the collection type across the web service, or a workaround i can implement client-side?

Thanks, Haden

Community
  • 1
  • 1

2 Answers2

0

AFAIK you cannot. Web reference doesn't allow List.

However if you change that to service reference you can do that by going to properties and specifying the collection type you want to use.

Ehsan
  • 31,833
  • 6
  • 56
  • 65
0

Suppose there is no way to do it by means of adding Web Reference. The XmlSerializer will convert all collections to Arrays and you can't avoid that. This is one of the features of data contaracts of WCF to specify the generated proxy collection's type, but it is available only when you use svcutil adding Service Reference. Suppose the only thing you can do, is to edit ypur contract by your hands, and specify the proper collection instead of array.

Alex
  • 8,827
  • 3
  • 42
  • 58