我有一个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" x
<?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;
}
}
}
}
我在我的webservice中返回一个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
