.NET auto-generated WSDL client does not handle abstract type when maxOccurs attribute is used

本小妞迷上赌 提交于 2020-01-26 02:49:07

问题


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>

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");
        }
    }

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.

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>

回答1:


Moving the maxOccurs attribute 'fixes' this.

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


来源:https://stackoverflow.com/questions/15819740/net-auto-generated-wsdl-client-does-not-handle-abstract-type-when-maxoccurs-att

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!