我有一个使用 VS2010 针对 .Net Framework 4 开发的 WCF Web 服务,它利用使用 xsd.exe 从 xsd 模式生成的序列化类。
当我从服务 (http://localhost:59120/Service1.svc?xsd=xsd2) 请求 xsd 时,元素属性被忽略。下面的架构片段中的 EG -
<xs:element name="id"...>
应该是一个属性 -
<xs:attribute name="id"...>
来自 xsd 请求的片段 -
...
<xs:sequence>
<xs:element name="address" type="xs:string" nillable="true"/>
<xs:element name="emailId" type="xs:string" nillable="true"/>
<xs:element name="id" type="xs:string" nillable="true"/>
<xs:element name="items" type="tns:ArrayOfArrayOfOrdersCustomerItemsItem" nillable="true"/>
<xs:element name="name" type="xs:string" nillable="true"/>
</xs:sequence>
...
由于某种原因,我的类中的语句“[XmlAttributeAttribute()]”被忽略了,我尝试将其更改为 [XmlAttribute()] 和 [XmlAttributeAttribute("Id")] 并完全删除该行,但在全部。
/// <remarks/>
[System.CodeDom.Compiler.GeneratedCodeAttribute("xsd", "4.0.30319.1")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[XmlTypeAttribute(AnonymousType = true)]
public partial class OrdersCustomer
{
/// <remarks/>
[XmlElementAttribute(Form = System.Xml.Schema.XmlSchemaForm.Unqualified, Order = 0)]
public string Name;
/// <remarks/>
[XmlElementAttribute(Form = System.Xml.Schema.XmlSchemaForm.Unqualified, Order = 1)]
public string Address;
/// <remarks/>
[XmlElementAttribute(Form = System.Xml.Schema.XmlSchemaForm.Unqualified, Order = 2)]
public string EmailId;
/// <remarks/>
[XmlArrayAttribute(Form = System.Xml.Schema.XmlSchemaForm.Unqualified, Order = 3)]
[XmlArrayItemAttribute("Item", typeof(OrdersCustomerItemsItem), Form = System.Xml.Schema.XmlSchemaForm.Unqualified, IsNullable = false)]
public OrdersCustomerItemsItem[][] Items;
/// <remarks/>
[XmlAttributeAttribute()]
public string Id;
}