我有一个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>
我已使用XSD.exe v2.0.50727.3615将其转换为C#类,其生成代码如下
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;
}
}
}
}
我在我的Web服务中返回一个A.A对象,该对象在服务描述中生成了此代码段
<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>
从XSD中的minOccrus =“ 1”更改为自动生成的WSDL的minOccurs =“ 0”导致系统另一端的计算机感到悲伤。
我当然可以提供手工编辑的WSDL供他们使用,但我希望自动生成的WSDL可以满足他们的需求。
关于如何说服dotnet在其自动生成的WSDL中为字符串类型输出minOccurs =“ 1”而又不添加nillable =“ true”的任何建议?
最佳答案
我注意到以下行:
为了将XML Schema复杂类型与非XML特定的类绑定在一起,.NET Framework不提供与minOccurs或maxOccurs属性等效的直接编程语言。
从这里:http://msdn.microsoft.com/en-us/library/zds0b35c(v=vs.85).aspx