I have a string field named "accountNumber" as part of an object used in a webservice. I need this field to have minOccurs="1"
but WITHOUT nillable="true"
.
If I define that field as <XmlElement(IsNullable:=True)>
then I get minOccurs="1"
and nillable="true"
. If I define <XmlElement(IsNullable:=False)>
then I don't get nillable="true"
, but I get minOccurs="0"
instead.
So, how do I define my object to get this in my XSD:
<s:element minOccurs="1" maxOccurs="1" name="accountNumber" type="s:string" />
My class definition is very simple:
<Serializable()> _
<XmlType(Namespace:="http://mysite.org")> _
Public Class MyServiceWS
'some other definitions
<XmlElement(IsNullable:=True)> <VBFixedString(64)> Public accountNumber As String
End Class
Thank you for any help.
EDIT Oct 16, 2012: reverse engineering XSD
I reverse engineered XSD with the following fields:
<xs:element name="TEST1" minOccurs="1" maxOccurs="1" type="xs:string"/>
<xs:element name="TEST2" minOccurs="0" maxOccurs="1" type="xs:string"/>
<xs:element name="TEST3" minOccurs="1" maxOccurs="1" nillable="true" type="xs:string"/>
<xs:element name="TEST4" minOccurs="0" maxOccurs="1" nillable="false" type="xs:string"/>
I used the following command: xsd.exe MyClass.xsd /classes /language:vb /f
The following results were produced:
'''<remarks/>
Public TEST1 As String
'''<remarks/>
Public TEST2 As String
'''<remarks/>
<System.Xml.Serialization.XmlElementAttribute(IsNullable:=true)> _
Public TEST3 As String
'''<remarks/>
Public TEST4 As String
Judging from this result, it doesn't seem to be possible to do what I want to accomplish.
EDIT Oct 17, 2012: found a post with similar issue
For all those interested in this issue, I found a post with similar problem. There was no solution provided.
How to make a dotnet webservice set minOccurs=“1” on a string value