none
Example of when to switch to XmlSerlizer RRS feed

  • Question

  • Hi I am reading this document on manually switching to XmlSerializer. Quote :"When precise control over the XML that appears in messages is important, but a Web Services Description Language (WSDL) document is not available, for example, when creating a service with types that have to comply to a certain standardized, published schema that is not compatible with the DataContractSerializer." I need example of xml schema which is not compatible with Data Contract Serializer.
    • Edited by kobosh3 Saturday, August 24, 2019 9:59 PM
    Saturday, August 24, 2019 9:59 PM

All replies

  • In my opinion, this existing standardized, published schema Based on the XML serialization.  Ordinarily, the custom data type during the communication between the server and the client should be explicitly marked data contract, this could be accomplished by the DataContract serialization, such as the below definition. 
    [DataContract]
        public class Product
        {
            [DataMember]
            public int ID { get; set; }
            [DataMember]
            public string Name { get; set; }
        }


    While the data could also be serialization by XML serialization, assumed that the below definition on the sever-side.
    public class Product
        {
            [XmlAttribute(AttributeName ="ID")]
            public int ID { get; set; }
            [XmlAttribute(AttributeName ="Name")]
            public string Name { get; set; }
    }


    Moreover, the service interface is decorated by the XmlSerializerFormat,
    [ServiceContract,XmlSerializerFormat]
        interface IService
        {
            [OperationContract]
            string GetData(Product product);
    }

    Under this circumstance, the data scheme on the client-side should be serialized with XML serializer, namely, it is not compatible with DataContract Serializer.
    Feel free to let me know if there is anything I can help with.
    Best Regards
    Abraham

    Monday, August 26, 2019 7:05 AM
    Moderator
  • thanks Abraham. Actually I wanted a scenario where Xml serialization must be used.

     
    Monday, August 26, 2019 1:18 PM
  • Hi,

    I am also not clearly understand the official document about the scenario that applies the Xml serialization. Ordinarily, the Data Contract serializier is preferred used in the latest WCF project. In my opinion, it might be that the xml serializier is used for the compatibility with the traditional XML web service(asmx) or some cross-platform web service based on the web service specification,

    https://en.wikipedia.org/wiki/Web_service

    Feel free to let me know if there is anything I can help with.

    Best Regards

    Abraham

    Tuesday, August 27, 2019 2:07 AM
    Moderator
  • Hi,
    I am also not clearly understand the official document about the scenario that applies the Xml serialization. Ordinarily, the Data Contract serializier is preferred used in the latest WCF project. In my opinion, it might be that the xml serializier is used for the compatibility with the traditional XML web service(asmx) or some cross-platform web service based on the web service specification, 
    https://en.wikipedia.org/wiki/Web_service
    Feel free to let me know if there is anything I can help with.
    Best Regards
    Abraham
    Tuesday, August 27, 2019 2:12 AM
    Moderator