title: Which must be used with XmlSerializer and WCF - DataContract or MessageContract?
body: <p>I need to write WCF service wich will take <b>.xml</b> file deserialize it into my custom calss and then do some operations on that data. I have written test version of this application which use console but not WCF. Here is how my code looks like:</p>
  
  <pre><code>[Serializable]
  public class ErrorMsgElement
  {
      [XmlElement("Sender")]
      public string SenderOfMessage{ get; set; }
  
      [XmlElement()]
      public Int64 UserID { get; set; }
  
      [XmlElement()]
      public Int64 SerialNumber { get; set; }
  
      [XmlElement("DateTime")]
      public DateTime DateAndTimeOfMessage { get; set; }
  }
  
  
  [Serializable]
  [XmlRoot("Root")]
  public class ErrorMessage
  {
      [XmlElement("Header")]
      public string HeaderOfFile { get; set; }
  
      [XmlElement("ErrorMsg")]
      public ErrorMsgElement msgElent { get; set; }
  }
  </code></pre>
  
  <p><b>And Main code</b></p>
  
  <pre><code>        ErrorMessage myErrorMsg = new ErrorMessage();
          //pathToFile is original path
          string path = @pathToFile;
  
          XmlSerializer myXmlSerializer = new XmlSerializer(typeof(ErrorMessage));
  
          using (StreamReader myStrReader = new StreamReader(path))
          {
              myErrorMsg = (ErrorMessage)myXmlSerializer.Deserialize(myStrReader);
          }
  
          //some operations on myErrorMsg such as writing to database
  </code></pre>
  
  <p>It works fine in console application. Now I need to write same logic in WCF service. But I don't know what should I use - <b>[Serializable]</b>, <b>[DataContact]</b>, <b>[MessageContract]</b> or someting else?. Consider that I have some [XmlArray] atributes in my custom classes as well. And if I add [DataContract] atribute to my <b>ErrorMessage</b> class do I have to add same attribute to <b>ErrorMsgElement</b> as following?</p>
  
  <pre><code>[DataContract]
  [Serializable]
  public class ErrorMsgElement
  {
      ...
  }
  
  [DataContract]
  [Serializable]
  [XmlRoot("Root")]
  public class ErrorMessage
  {
      ...
  
      [DataMember]
      [XmlElement("ErrorMsg")]
      public ErrorMsgElement msgElent { get; set; }
  }
  </code></pre>
  
  <p>All answers are well appreciated. Thanks in advance.</p>