.NET 自动生成的 WSDL 客户端在使用 maxOccurs 属性时不处理抽象类型 [英] .NET auto-generated WSDL client does not handle abstract type when maxOccurs attribute is used

查看:22
本文介绍了.NET 自动生成的 WSDL 客户端在使用 maxOccurs 属性时不处理抽象类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个相当复杂的 WSDL,我将它添加为 Visual Studio 中的服务引用.我遇到的问题是自动生成的客户端代码没有正确处理抽象类型(并忽略替代该抽象类型的所有类型).我不想发布整个 WSDL,但这里有一个片段:

I have a rather complicated WSDL that I am adding as a service reference in Visual Studio. The problem I am having is that the auto-generated client code is not properly handling an abstract type (and ignoring all the types that substitute for that abstract type). I don't want to post the entire WSDL but here is a snippet:

<complexType name="AddTextFields">
    <complexContent>
        <extension base="ti:TransformationInstructions">
            <sequence>
                <element name="textFieldList"
                    type="atf:TextFieldList" />
            </sequence>
        </extension>
    </complexContent>
</complexType>

<complexType name="TextFieldList">
    <sequence>
        <element ref="atf:TextFieldBase"
            maxOccurs="unbounded" />
    </sequence>
</complexType>

<element name="TextFieldBase" abstract="true"/>

<element name="textField" substitutionGroup="atf:TextFieldBase">
  <complexType>
    <sequence>
      ...
    </sequence>
  </complexType>
</element>

<element name="checkBox" substitutionGroup="atf:TextFieldBase">
  <complexType>
    <sequence>
      ...
    </sequence>
  </complexType>
</element>

所以你可以在这里看到 TextFieldList 可以有无限的 TextFieldBase 类型的元素(可以是 textField、checkBox 和我省略的其他一些元素).但是,在创建 WSDL 客户端时,.NET 似乎并不关心这一点,而是像这样生成 textFieldList:

So you can see here TextFieldList can have unlimited elements of type TextFieldBase (which can be textField, checkBox and some others that I omitted). However, when creating the WSDL client, .NET doesn't seem to care about this and generates textFieldList like so:

[System.Xml.Serialization.XmlArrayAttribute(Order=0)]
    [System.Xml.Serialization.XmlArrayItemAttribute("TextFieldBase", IsNullable=false)]
    public object[] textFieldList {
        get {
            return this.textFieldListField;
        }
        set {
            this.textFieldListField = value;
            this.RaisePropertyChanged("textFieldList");
        }
    }

我在 WSDL 中有一些其他抽象类型可以正常工作,在尝试比较它们时,我发现如果从 TextFieldList 中删除 ma​​xOccurs="unbounded" 属性> 定义,然后 .NET 将正确生成插入抽象类型的类型.不幸的是,我们需要能够有 1 个或多个 textFieldList 元素,这样就行不通了.

I have some other abstract types in the WSDL that do work correctly and in trying to compare them I discovered that if I remove the maxOccurs="unbounded" attribute from TextFieldList definition, then .NET will correctly generate the types that plug into the abstract type. Unfortunately, we need to be able to have 1 or more textFieldList elements so that will not work.

这只是 .NET 中的一个错误吗?或者是否有一些解决方法可以在不彻底改变 WSDL 的情况下工作?

Is this just a bug in .NET? Or is there some workaround that would work without drastically changing the WSDL?

我考虑的一种解决方法是将实现更改为一种选择,而不是使用抽象:

One workaround I considered was changing the implementation to be a choice instead of using abstract:

<complexType name="TextFieldList">
<choice maxOccurs="unbounded">
    <element ref="atf:textField" />
    <element ref="atf:checkBox" />
    <element ref="atf:radioButtonGroup" />
    <element ref="atf:listBox" />
    <element ref="atf:comboBox" /> 
</choice>
</complexType>

推荐答案

移动 maxOccurs 属性修复"了这个问题.

Moving the maxOccurs attribute 'fixes' this.

<complexType name="TextFieldList">
    <sequence maxOccurs="unbounded">
        <element ref="atf:TextFieldBase" />
    </sequence>
</complexType>

这篇关于.NET 自动生成的 WSDL 客户端在使用 maxOccurs 属性时不处理抽象类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆