daniloquio
daniloquio

Reputation: 3912

Proxy classes exposing the wrong type

I have a web service method that expects a parameter of type OnlinePaymentResponse. This type includes a property of type CustomData, like this:

[Serializable]
public class OnlinePaymentResponse
{        
   public CustomData CustomData { get; set; }
}

CustomData class is like this:

[XmlType(Namespace = XmlConstants.Namespace)]
public class CustomData
{
    public CustomData()
    {
        this.Tables = new List<DynamicTable>();
    }

    [XmlElement("DynamicTable")]
    public List<DynamicTable> Tables { get; set; }

    .....

Problem is, when I generate the proxy with svcutil.exe, insted of getting the CustomData type I'm getting an array of DynamicTable.

public partial class OnlinePaymentResponse
{    
    private DynamicTable[] customDataField;

    ..........

I've been playing with it and found that if I remove the XmlElement attribute of the Tables property, it will generate the proxy class properly:

public partial class OnlinePaymentResponse
{    
    private CustomData customDataField;

    ..........

I don't understand why does it happen. I've been playing with DataContract, DataMember, XmlRoot and other attributes but I haven't been able to get the proxy right without removing the XmlElement attribute. What am I missing here?

Upvotes: 0

Views: 75

Answers (1)

Ricardo Pontual
Ricardo Pontual

Reputation: 3757

Svcutil try to generate a class not to be coupled to .NET. type, so an array is a common type that can be use for other platforms.

You can create a with CollectionDataContract attribute (see more here: CollectionDataContract attribute) and inherits from List, it will generate a complex that is not an array.

Upvotes: 0

Related Questions