DataContract is the default serialization programming model for WCF. However WCF supports more than just the types marked wth DataContract attribute. It supports serialization of the following kinds of types in the default mode.
Some types may implement more than one of the above programming model. In such cases a programming model is chosen based on its priority as given by the above list. For example,Hashtable is a collection class but also implements ISerializable and it is serialized as a collection type. DataSet implements both IXmlSerializable and ISerializable and it is serialized as IXmlSerializable.
you can manually switch to the XmlSerializer class by applying the XmlSerializerFormatAttributeattribute to your service
[Serializable] public class CustomerISerializable : ISerializable { public string Id { get; set; } public string Name { get; set; } public CustomerISerializable() { } public void GetObjectData(SerializationInfo info, StreamingContext context) { info.AddValue("Id", Id); info.AddValue("Name", Name); } protected CustomerISerializable(SerializationInfo info, StreamingContext context) { Id = info.GetString("Id"); Name = info.GetString("Name"); } }
but you shoule add XmlSerializerFormatAttributeattribute to your service
[ServiceContract] interface ICustomerServices { [OperationContract] [XmlSerializerFormat] string GetCustomer(CustomerISerializable c); }
As MSDN metioned . When you want to switch to XmlSerializer from the default for the serialization .You should apply the XmlSerializerFormatAttribute .
However. As i know. Serializable Attribute and Implement ISerializable interface is only useful in the binary serialization . so .Why need apply XmlSerializerFormatAttribute in the WCF when we apply Serializable Attribute or implement ISerializable interface in the types.
otherwise this method will be not available. because of using this kind of type.(Serializble or ISerializable)
Can anyone tell me why ?
refer to :http://www.codeproject.com/Articles/30279/Serialization-in-Windows-Communication-Foundation
http://www.cnblogs.com/chnking/archive/2008/06/06/1215411.html
http://www.cnblogs.com/chnking/archive/2008/02/25/1081417.html(soapformat and binary format in serialization)
http://msdn.microsoft.com/en-us/library/system.serializableattribute.aspx