Diffgram,XML and writeXML

G

Guest

Hi guys,

whats wrong with below code!!!!!! it just doesn't work

All i want to do is Return my typed dataset as diffgram in bytes and receive
it in my PPC application and convert it back to dataset

WebService code Snippet:

myDsHandIT2.WriteXml(stream, XmlWriteMode.DiffGram)
myBytes = stream.ToArray()
return myBytes

PPC Code Snippet :


Dim myBytes() As Byte
Try
myBytes = objHandIT2.TestLoadData(Me.mUsername, Me.mPassword,

Me.mWebServiceUrl, Me.IPAddress)
strresult = utf.GetString(myBytes, 0, myBytes.Length)
Me.writeXML(strresult, "\Program Files\Data\test.xml", "\Program
Files\Data\test.xsd")
Catch ex As Exception
MessageBox.Show(ex.ToString)
End Try


Public Function writeXML(ByVal myStream As String, ByVal FileName As
String, ByVal SchemaName As String) As Boolean

Dim stream As StreamWriter = Nothing
Dim writer As XmlTextWriter = Nothing
Dim isOk As Boolean
Dim ds As New DataSet

Try
stream = New StreamWriter(myStream) <---------- Goes bang over
here
writer = New XmlTextWriter(stream)

If (Not (ds.Tables.Count = 0)) Then
' Save out to file
ds.WriteXml(writer, XmlWriteMode.DiffGram)
'write schema also
ds.WriteXmlSchema(SchemaName)
End If

isOk = True
Catch ex As Exception
isOk = False
MessageBox.Show(ex.ToString)
Finally
If Not (stream Is Nothing) Then
stream.Close()
End If
End Try
Return isOk
End Function

Regards

Salim
 
G

Guest

StreamWriter doesn't accept a xml data string in it's constructor, it's a
path to the file. Instead, you could use the MemoryStream:

Dim ms As MemoryStream = NewMemoryStream(myBytes)

writer = New XmlTextWriter(ms)

HTH... Alex
 
I

Ilya Tumanov [MS]

If you return a DataSet directly, it will be serialized as a diffgram
anyway.
I would suggest dropping byte array idea as it would cause serious
performance hit for double serialization/deserialization without really
affecting data over wire.

If you have problems returning typed DataSet, you can:

a) Change your web method to return untyped DataSet.
b) Tweak the proxy code so it would use untyped DataSet.
c) Tweak typed DataSet code so it would work on CF (or use CF typed DataSet
generator freely available on the web).

Best regards,

Ilya

This posting is provided "AS IS" with no warranties, and confers no rights.

--------------------
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top