问题
We have a big wcf service, and a big xsd document where we have several elements and complex types. We generate code with the xsd.exe, and use the XmlSerializerFormat
on our ServiceContract
for the WCF service to serialize these objects again.
Now we have a problem with xsd.exe and the definitions of an array of strings.
Image we have the following element defined..
<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>
which will result in:
/// <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;
}
As you can see, the xsd.exe tool is smart enough to see the complextype Parameters
, so it makes it a string[]
.
The problem is, that if we use this in our WCF service, it will create ArrayOfString
complextypes instead of our Parameters
complex type. Even worse, we have several string[] resulting in ArrayOfString1
, ArrayOfString2
, ArrayOfString3
and so forth..
The question is: How can we avoid that XSD flattens our Parameters
complextype?
来源:https://stackoverflow.com/questions/13761543/xsd-exe-ignores-simple-complextypes