2

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

Community
  • 1
  • 1
George
  • 2,165
  • 2
  • 22
  • 34
  • I would suggest to do the reverse: create a dummy XML Schema that has the XSD content the way you want it, then run xsd.exe using the vb language settings to generate the code, and then take a look at what was generated for additional hints. – Petru Gardea Oct 15 '12 at 19:58
  • Already tried that - they seem to be the same. – George Oct 15 '12 at 20:37
  • So are you saying that for that, you're getting a different minOccurs? i.e. is the roundtrip engineering that also doesn't work, which is reversing from XSD into VB.NET and forward engineering from the VB code into XSD gives you different results? – Petru Gardea Oct 15 '12 at 22:06
  • I did it an other way... Please see my edit. – George Oct 16 '12 at 13:35

2 Answers2

0

As far as I know, what I am asking is not possible to automate through .NET. I would have to alter the WSDL manually.

George
  • 2,165
  • 2
  • 22
  • 34
0

I have posted a detailed answer on another thread with the same problem: How to make a dotnet webservice set minOccurs=“1” on a string value.

However the short answer is no. It's not possible for string types.

String types have a default value of String.Empty, and minOccurs won't be set to 1 unless there is no default value (which is only possible using IsNullable = true for string).

Community
  • 1
  • 1
Rapps
  • 142
  • 1
  • 6