XSD.exe忽略简单的复杂类型

时间:2012-12-07 10:47:11

标签: c# wcf xsd xsd.exe

我们有一个很大的wcf服务和一个大的xsd文档,其中我们有几个元素和复杂类型。我们使用xsd.exe生成代码,并使用XmlSerializerFormat上的ServiceContract作为WCF服务再次序列化这些对象。

现在我们遇到了xsd.exe和字符串数组定义的问题。

图片我们定义了以下元素..

<xs:element name="Configuration" type="Configuration"/>
<xs:complexType name="Configuration">
    <xs:sequence>
    <xs:element name="Name" type="xs:string"/>
    <xs:element name="Parameters" type="Parameters" />
    </xs:sequence>
  </xs:complexType>

  <xs:complexType name="Parameters">
     <xs:sequence>
    <xs:element name="Parameter" type="xs:string" maxOccurs="unbounded"/>
      </xs:sequence>
  </xs:complexType>

将导致:

 /// <remarks/>
    [System.CodeDom.Compiler.GeneratedCodeAttribute("xsd", "2.0.50727.3038")]
    [System.SerializableAttribute()]
    [System.Diagnostics.DebuggerStepThroughAttribute()]
    [System.ComponentModel.DesignerCategoryAttribute("code")]
    [System.Xml.Serialization.XmlTypeAttribute(Namespace="http://mynamespace.com/")]
    [System.Xml.Serialization.XmlRootAttribute(Namespace="http://mynamespace.com/", IsNullable=false)]
    public partial class Configuration {

        /// <remarks/>
        [System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified)]
        public string Name;

        /// <remarks/>
        [System.Xml.Serialization.XmlArrayAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified)]
        [System.Xml.Serialization.XmlArrayItemAttribute("Parameter", Form=System.Xml.Schema.XmlSchemaForm.Unqualified, IsNullable=false)]
        public string[] Parameters;
    }

正如您所看到的,xsd.exe工具非常智能,可以看到复杂类型Parameters,因此它使其成为string[]

问题是,如果我们在WCF服务中使用它,它将创建ArrayOfString复杂类型而不是我们的Parameters复杂类型。更糟糕的是,我们有几个字符串[]产生ArrayOfString1ArrayOfString2ArrayOfString3等等。

问题是:我们如何避免XSD压扁我们的Parameters复杂类型?

0 个答案:

没有答案