Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/wcf/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/web-services/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
忽略WCF Web服务xml序列化[XmlAttributeAttribute()]_Wcf_Web Services_Xsd_Xml Attribute - Fatal编程技术网

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

忽略WCF Web服务xml序列化[XmlAttributeAttribute()],wcf,web-services,xsd,xml-attribute,Wcf,Web Services,Xsd,Xml Attribute,我有一个使用VS2010开发的WCF web服务,目标是.Net Framework 4,它利用从使用xsd.exe的xsd模式生成的序列化类 当我从服务请求xsd时(http://localhost:59120/Service1.svc?xsd=xsd2)元素属性将被忽略。例如,在下面的模式片段中- <xs:element name="id"...> 应该是一个属性- <xs:attribute name="id"...> xsd请求的代码段- ... &l

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

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

<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;
    }
//
[System.CodeDom.Compiler.GeneratedCodeAttribute(“xsd”,“4.0.30319.1”)]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute(“代码”)]
[XmlTypeAttribute(AnonymousType=true)]
公共部分类OrdersCustomer
{
/// 
[XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified,Order=0)]
公共字符串名称;
/// 
[XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified,Order=1)]
公共字符串地址;
/// 
[XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified,Order=2)]
公共字符串EmailId;
/// 
[XmlArrayAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified,Order=3)]
[XmlArrayItemAttribute(“Item”,typeof(OrdersCustomerItemsItem),Form=System.Xml.Schema.XmlSchemaForm.Unqualified,IsNullable=false]
公共秩序网站[]项目;
/// 
[XmlAttributeAttribute()]
公共字符串Id;
}

确保您的
[ServiceContract]
接口具有
[XmlSerializerFormat]
属性。如果这不存在,那么WCF将使用
DataContractSerializer
,您的
XmlSerializer
属性将被忽略。

非常感谢,已经查找了近3周,昨晚我在发布问题后发现了这篇文章