2

xsd.exeを使用してxsdスキーマから生成されたシリアル化クラスを利用する.NetFramework4を対象とするVS2010で開発されたWCFWebサービスがあります。

サービス(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;
    }
4

1 に答える 1

6

[ServiceContract]インターフェイスに[XmlSerializerFormat]属性があることを確認してください。これが存在しない場合、WCFはを使用しDataContractSerializer、すべてのXmlSerializer属性が無視されます。

于 2012-12-20T17:02:02.887 に答える