代理类暴露错误的类型

时间:2021-11-24 17:00:26

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

我有一个Web服务方法,需要一个类型为OnlinePaymentResponse的参数。此类型包含CustomData类型的属性,如下所示:

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

CustomData class is like this:

CustomData类是这样的:

[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.

问题是,当我用svcutil.exe生成代理时,得到了CustomData类型,我得到了一个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:

我一直在玩它,发现如果我删除Tables属性的XmlElement属性,它将正确生成代理类:

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?

我不明白为什么会这样。我一直在玩DataContract,DataMember,XmlRoot和其他属性但是我没有删除XmlElement属性就无法获得代理权限。我在这里想念的是什么?

1 个解决方案

#1


0  

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.

Svcutil尝试生成一个不与.NET耦合的类。类型,因此数组是可用于其他平台的常见类型。

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.

您可以使用CollectionDataContract属性创建一个(请参阅此处:CollectionDataContract属性)并从List继承,它将生成一个不是数组的复合体。

#1


0  

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.

Svcutil尝试生成一个不与.NET耦合的类。类型,因此数组是可用于其他平台的常见类型。

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.

您可以使用CollectionDataContract属性创建一个(请参阅此处:CollectionDataContract属性)并从List继承,它将生成一个不是数组的复合体。