The serialization in data contract to xml is little different in WCF model than traditional xml serialization. Here is 2 method I used in my custom WCF handler.
Imports System.Runtime.Serialization
Public Shared Function DeserializeObject(ByRef xmlizedString As String, ByRef objectType As Type) As Object
Dim memoryStream As New MemoryStream(StringToUTF8ByteArray(xmlizedString))
Dim dcs As New DataContractSerializer(objectType)
Return Convert.ChangeType(dcs.ReadObject(memoryStream), objectType)
End Function
Public Shared Function SerializeObject(ByRef xmlizableObject As Object, ByRef objectType As Type) As Object
Dim memoryStream As New MemoryStream()
Dim dcs As New DataContractSerializer(objectType)
dcs.WriteObject(memoryStream, xmlizableObject)
Return UTF8ByteArrayToString(memoryStream.ToArray())
End Function
sample code fragment to use the method :
dim student a new Student
dim studentData as string
studentData =SerializeObject(student , GetType(Student))
Tuesday, April 1, 2008
Subscribe to:
Posts (Atom)