You are not logged in.
Pages: 1
Given the different options of serialization in .NET, which one would you consider the most efficient? The ones I know of are the following:
- XmlSerializer
- Binary serialization
- DataContractSerializer & NetDataContractSerializer
- Custom serializer
Your thoughts?
Do you care about performance or size?
DataContract are aimed at interoperability. NetDataContract is aimed at WCF data service serialization with clients that are .NET compatible (AFAIK). The rest is obvious.
Do you care about performance or size?
DataContract are aimed at interoperability. NetDataContract is aimed at WCF data service serialization with clients that are .NET compatible (AFAIK). The rest is obvious.
I care about performance. Which one performs better than all the others?
Binary Serialization is the fastest.
Check out http://code.google.com/apis/protocolbuf … rview.html @googlecode
Last edited by Joe3dr (December 7 2011)
Reviving an old post!!
I am currently working on a personal project.
I've created a WCF service and I decided to use the same return for all the method
The return class is:
[DataContract]
[Serializable]
public class ServiceOutputDC
{
/// <summary>
/// Client should always check for errors first
/// </summary>
[DataMember]
public bool Faultless { get; set; }
[DataMember]
public List<DataContract.GlobalDataContract.ErrorDC> Error { get; set; }
[DataMember]
public List<DataContract.GlobalDataContract.DataDC> Data { get; set; }
public ServiceOutputDC()
{
Error = new List<ErrorDC>();
Data = new List<DataDC>();
}
}
Where Error is:
[DataContract]
[Serializable]
public class ErrorDC
{
[DataMember]
public string Error { get; set; }
[DataMember]
public string ErrorMsg { get; set; }
}
and data is
[DataContract]
[Serializable]
public class DataDC
{
[DataMember]
public string DataKey { get; set; }
[DataMember]
public byte[] Data { get; set; }
}
I faced a problem while trying to send "object" type. that's why I've used byte[] instead of "object".
The functions used to serialize and deserialize are:
public byte[] Serialize(object input)
{
BinaryFormatter BF = new BinaryFormatter();
byte[] output;
using (var MemStream = new MemoryStream())
{
BF.Serialize(MemStream, input);
output = MemStream.ToArray();
}
return output;
}
public object DeSerializer(byte[] input)
{
object output;
using (var MemStream = new MemoryStream())
{
BinaryFormatter BF = new BinaryFormatter();
MemStream.Write(input, 0, input.Length);
MemStream.Seek(0, SeekOrigin.Begin);
output = BF.Deserialize(MemStream);
}
return output;
}
Any thoughts?
Pages: 1