I have an XSD:
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns="http://a.com/a.xsd"
targetNamespace="http://a.com/a.xsd"
elementFormDefault="qualified"
attributeFormDefault="unqualified">
<xs:element name="A">
<xs:complexType>
<xs:sequence>
<xs:element name="Item" minOccurs="1" maxOccurs="1">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:minLength value="1"/>
<xs:whiteSpace value="collapse"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
Which I have converted into a C# class using XSD.exe v2.0.50727.3615 which generates code as follows
namespace A {
using System.Xml.Serialization;
/// <remarks/>
[System.CodeDom.Compiler.GeneratedCodeAttribute("xsd", "2.0.50727.42")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(AnonymousType=true, Namespace="http://a.com/a.xsd")]
[System.Xml.Serialization.XmlRootAttribute(Namespace="http://a.com/a.xsd", IsNullable=false)]
public partial class A {
private string itemField;
/// <remarks/>
public string Item {
get {
return this.itemField;
}
set {
this.itemField = value;
}
}
}
}
I am returning an A.A object in my webservice, which produces this snippet in the service description
<s:schema elementFormDefault="qualified" targetNamespace="http://a.com/a.xsd">
<s:element name="Test2Result">
<s:complexType>
<s:sequence>
<s:element minOccurs="0" maxOccurs="1" name="Item" type="s:string" />
</s:sequence>
</s:complexType>
</s:element>
</s:schema>
The change from minOccrus="1" in the XSD to minOccurs="0" on the auto-generated WSDL is causing grief to the machine on the other end of the system.
I could of course provide a hand edited WSDL for them to use, but I would like the auto-generated one to suit their needs.
Any suggestions on how to convince dotnet to output minOccurs="1" for a string type in its autogenerated WSDLs without also adding nillable="true"?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…