I'm writing some unit tests that serialize and deserialize all of our types that might cross the WCF boundary, in order to prove that all properties will make it to the other side.
I've hit a bit of a snag with a byte[] property.
[DataContract(IsReference=true)]
public class BinaryDataObject
{
[DataMember]
public byte[] Data { get; set; }
}
When I run this object through the testing, I get System.NotSupportedException: This XmlWriter does not support base64 encoded data
.
Here's my Serialization method:
public static XDocument Serialize(object source)
{
XDocument target = new XDocument();
using (System.Xml.XmlWriter writer = target.CreateWriter())
{
DataContractSerializer s = new DataContractSerializer(source.GetType());
s.WriteObject(writer, source);
}
return target;
}
It occurs to me that my serialization method must be flawed - WCF probably doesn't use XDocument
instances and might not use System.Xml.XmlWriter
instances.
What Writer does WCF use by default? I'd like to use instances of that type in my test.