527 messaggi dal 18 dicembre 2012
Ciao a tutti
Ho un servizio WCF che deve restituire una risposta con il seguente schema xml:
<ConfigurationResponse>
  <RoomTypes>
    <RoomType id="5">
      <Description>Singola</Description>
      <Rates>
        <Rate id="10">
          <Description>Standard</Description>
        </Rate>
      </Rates>
    </RoomType>
    <RoomType id="6">
      <Description>Doppia</Description>
      <Rates>
        <Rate id="10">
          <Description>Standard</Description>
        </Rate>
        <Rate id="11" parent="10">
          <Description>Not Ref</Description>
        </Rate>
      </Rates>
    </RoomType>
  </RoomTypes>
</ConfigurationResponse>


Ho trasformato questo schema in una classe per poter facilmente inserire i dati:
[System.SerializableAttribute()]
[XmlTypeAttribute(AnonymousType=true)]
[XmlRootAttribute(Namespace="", IsNullable=false)]
public partial class ConfigurationResponse {

    public ConfigurationResponse()
    {
        RoomTypes = new List<tipoRoomType>();
    }    
    
    [XmlArrayItemAttribute("RoomType", IsNullable=false)]
    public List<tipoRoomType> RoomTypes {
        get;

        set;
    }

}

[System.SerializableAttribute()]
[XmlTypeAttribute(AnonymousType=true)]
public partial class tipoRoomType {

    public tipoRoomType()
    {
        Rates = new List<tipoRoomTypeRate>();
    }

    public string Description {
        get;

        set;
    }    

    [XmlArrayItemAttribute("Rate", IsNullable=false)]
    public List<tipoRoomTypeRate> Rates {
        get;

        set;
    }    

    [XmlAttributeAttribute()]
    public string id {
        get;

        set;
    }
}

[System.SerializableAttribute()]
[XmlTypeAttribute(AnonymousType=true)]
public partial class tipoRoomTypeRate {      

    public string Description {
        get;

        set;
    }    

    [XmlAttributeAttribute()]
    public string id {
        get;

        set;
    }    

    [XmlAttributeAttribute()]
    public string parent {
        get;

        set;
    }    

    [XmlIgnoreAttribute()]
    public bool parentSpecified {
        get;

        set;
    }
}


Ora devo definire il [DataContract]. Definisco il [DataContract] solo per la classe che rappresenta il nodo radice?
[DataContract]
    [System.SerializableAttribute()]
    [XmlTypeAttribute(AnonymousType = true)]
    [XmlRootAttribute(Namespace = "", IsNullable = false)]
    public partial class ConfigurationResponse
    {
        public ConfigurationResponse()
        {
            RoomTypes = new List<tipoRoomType>();
        }

        [DataMember]
        [XmlArrayItemAttribute("RoomType", IsNullable = false)]
        public List<tipoRoomType> RoomTypes
        {
            get;

            set;
        }

    }


O per tutte le classi?

Grazie mille

Torna al forum | Feed RSS

ASPItalia.com non è responsabile per il contenuto dei messaggi presenti su questo servizio, non avendo nessun controllo sui messaggi postati nei propri forum, che rappresentano l'espressione del pensiero degli autori.