1

I am using VS2010 and using the "add service reference" feature, to generate client classes from my WSDL. I am having a problem with one of my elements, which is defined in the WSDL as follows:

<xs:simpleType name="NumberType">
    <xs:restriction base="xs:string">
        <xs:enumeration value="ONE" /> 
        <xs:enumeration value="TWO" /> 
        <xs:enumeration value="THREE" /> 
    </xs:restriction>
</xs:simpleType>

This type is used in one of my elements like this:

<xs:element name="NumberTypes">
    <xs:simpleType>
        <xs:list itemType="tns:NumberType" /> 
    </xs:simpleType>
</xs:element>

The problem is that VS is converting this particular element to a string type, when it should be an enumeration. so it converts it to a string NumberTypes which has a get method returning numberTypesField also of type string.

I think the problem is related to the fact that my schema NumberTypes element uses the xs:list, with 'itemType' attribute. if I change this to xs:element with type="tns:NumberType" attribute instead then the enumeration is generated as it should be.

So how can I make the enumeration work with xs:list? Why is it not converting correctly in the first place?

Thanks for any help.

1
  • ah ah!, the big lie of interoperability and standards. I loose some hair with making java speak to .Net. Good luck Commented Jul 24, 2012 at 12:20

1 Answer 1

1

I haven't had much luck getting xs:list to serialize properly. Instead, I just allow for multiple instances of the same node, and .NET knows how to put it into a "list" or "array" properly.

<xs:element minOccurs="0" maxOccurs="unbounded" name="NumberTypes">
    ...
</xs:element>
Sign up to request clarification or add additional context in comments.

4 Comments

Oh thanks, that works :) hmm it now generates the enum correctly (NumberType) and also generates a NumberTypes element which has the type NumberType[] ... array is a bit hard to work with - is it possible to make .NET generate a list instead? otherwise I have to resize the array to add to it, or initialise it to the size of the enum even though there may not be that many elements. Is there a better way?
it's not working though - no matter what I select in the collections type dropdown (arraylist, generic list etc) it always continues to generate arrays. any ideas what's wrong? the generated code looks like this always: /// <remarks/> [System.Xml.Serialization.XmlElementAttribute("NumberTypes", Order=0)] public NumberType[] NumberTypes { get { return this.numberTypesField; } set { this.numberTypesField = value; this.RaisePropertyChanged("NumberTypes"); } }
well apparently it's because my schema requires XMLSerializer instead of DataContractSerializer (which can generate lists). so does this mean I have to work with arrays? :s
It seems like arrays are what .NET wants you to use, although there are some tricks based on how you are using the serialized objects. This article helps to clarify: raypendergraph.wikidot.com/article:basic-cs-xml-serialization See the "To-Many" relationships section.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.