小编All*_*are的帖子

WCF Web服务xml序列化[XmlAttributeAttribute()]被忽略

我有一个使用VS2010开发的WCF Web服务,目标是.Net Framework 4,它使用xsd.exe从xsd架构生成的序列化类.

当我从服务请求xsd时(http:// localhost:59120/Service1.svc?xsd = xsd2),将忽略元素属性.EG在下面的架构片段中 -

<xs:element name="id"...>
Run Code Online (Sandbox Code Playgroud)

应该是一个属性 -

<xs:attribute name="id"...>
Run Code Online (Sandbox Code Playgroud)

来自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>
...
Run Code Online (Sandbox Code Playgroud)

由于某种原因,我的类中的语句"[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;

        /// …
Run Code Online (Sandbox Code Playgroud)

wcf xsd web-services xml-attribute

2
推荐指数
1
解决办法
2241
查看次数

标签 统计

wcf ×1

web-services ×1

xml-attribute ×1

xsd ×1