How can I fix the web link proxy generated by Visual Studio for processing jagged arrays?

There seems to be a known bug in wsdl.exe, a tool that Visual Studio uses to create web service proxies. Using some XSD schemas, the tool will generate classes that cannot be deserialized from XML.

As far as I understand, this is unacceptable, but I do not know how to fix it.

I will tell you in detail about my case, I hope someone can help me.

Scheme

<!-- return type from the service operation -->
<xs:complexType name="listAssetsQueryResults">
    <xs:sequence>
        <xs:element name="assets" type="tns:asset" minOccurs="0" maxOccurs="unbounded"/>
    </xs:sequence>
</xs:complexType>

<!-- a sequence of attributes -->
<xs:complexType name="asset">
    <xs:sequence>
        <xs:element name="attributes" type="tns:multiValuedAttribute" minOccurs="0" maxOccurs="unbounded"/>
    </xs:sequence>
</xs:complexType>

<xs:complexType name="multiValuedAttribute">
    <!-- not relevant-->
</xs:complexType>

Web service XML response

A typical answer according to this scheme is as follows:

<assets-query-result>
    <assets>
        <attributes>
            <name>Keywords</name>
            <values>Desert</values>
        </attributes>
        <attributes>
            <name>Filename</name>
            <values>Desert.jpg</values>
        </attributes>
    </assets>
    <assets>...</assets>
    <assets>...</assets>
</assets-query-result>

Using types in code

I expected that I could use CLR types as follows:

result.assets[0].attributes[0].name

Instead, the generated type for the result is as follows:

[SerializableAttribute()]
public partial class listAssetsQueryResults {
    private multiValuedAttribute[][] assetsField;

    [XmlArrayAttribute(Form=XmlSchemaForm.Unqualified, IsNullable=true)]
    [XmlArrayItemAttribute("attributes", typeof(multiValuedAttribute), Form=XmlSchemaForm.Unqualified)]
    public multiValuedAttribute[][] assets {
        get { return this.assetsField; }
        set { this.assetsField = value; }
    }
}

This does not even allow the serialization assembly to be generated!

Portfolio.WebService.multiValuedAttribute .WebService.multiValuedAttribute []

1 -

, , - :

// No longer a jagged array, but this doesn't deserialize all data
public multiValuedAttribute[] assets;

, , , , "" assets. , . 700 + result.assets multiValuedAttribute[2] (2 - ).

2 - XML-

, , - :

[XmlArrayItemAttribute("attributes", typeof(multiValuedAttribute[]), Form=XmlSchemaForm.Unqualified)]
public multiValuedAttribute[][] assets { ... }

, , multiValuedAttribute[]. , attributes, multiValuedAttribute (, ). , result.assets multiValuedAttribute[2][0], .

?

, . , .NET -, .

+5
3

, Asset, multiValuedAttribute []. ,

public class Asset
{
   public multiValuedAttribute[] attributes {get; set;}
}

public partial class listAssetsQueryResults {
    private Asset[] assetsField;

    public Asset[] assets {

, XmlElement/XmlArrayElement/XmlArrayItemElement, .

, , -, (, script ).

+3

- SOAP, Java, WCF, #,.Net .., ( ). VinayC , , , , .

, . , WSDL, .

public partial class assests{
  private multiValuedAttribute[] attributesField;
  [System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified)]
  public multiValuedAttribute[] attributes{
    get {return this.attributesField;}
    set {this.attributesField = value;}
  }
}

public partial class listAssetsQueryResults{
  private assests[] assetsField;
  [System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified)]
  public assets[] assets{
      get {return this.assetsField;}
      set {this.assetsField = value;}
  }
}

"", multiValuedAttribute listAssetsQueryResults, XmlElementAttribute. - , multiValuedAttribute ( ). multiValuedAttribute "" , . [] , [] [] listAssetsQueryResults. XmlElement XmlArrayItem.

, . Fiddler (http://fiddler2.com/) , , . . , : http://msdn.microsoft.com/en-us/library/2baksw0z.aspx

+2

, - - wsdl. , KeyValuePair<string, string> - , -.

, , API , .

, .NET -

Well, as my friend Mother Teresa says: “Life is a struggle, accept it” .; -)

0
source

All Articles