.net - Testing DataContractSerializer with String -
i'm testing sending complex message object on wcf service , getting various serialization errors. in order simplify things i'm trying cut down testing datacontractserializer
, i've written following test based on code here:
dim message tlamessage = mockfactory.getmessage dim dcs datacontractserializer = new datacontractserializer(gettype(tlamessage)) dim xml string = string.empty using stream new stringwriter(), writer xmlwriter = xmlwriter.create(stream) dcs.writeobject(writer, message) xml = stream.tostring end using debug.print(xml) dim newmessage tlamessage dim sr new stringreader(xml) dim reader xmlreader = xmlreader.create(sr) dcs = new datacontractserializer(gettype(tlamessage)) newmessage = ctype(dcs.readobject(reader, true), tlamessage) 'error here reader.close() sr.close() assert.istrue(newmessage isnot nothing)
however gets unusual error in on call readobject
: unexpected end of file while parsing name has occurred. line 1, position 6144
it appears buffering error can't see how 'readtoend' on string. i've tried using memorystream
: dim ms new memorystream(encoding.utf8.getbytes(xml))
, streamwriter
each of has come own errors or not compatible readobject
method of datacontractserializer
takes variety of different overloads.
note adapting code msdn page works fine requires serializing file, wanted serialize , string think i'm missing vital.
am missing obvious in code above?
the data xmlwriter
not populated underlying stringwriter
. should flush writer after writing:
dcs.writeobject(writer, message) writer.flush() xml = stream.tostring()
Comments
Post a Comment