Use DIME/attatchment to download an application

G

Guest

Hi
I have no problem downloading an image with Web Services Enhancements and
the DIME specification, but how do I dowwnload an application?
Regards
/Niklas

Web service:

<WebMethod()> _
Public Sub CreateDimedApplication(ByVal FileName As String)
Dim sendFile As System.IO.FileStream
sendFile = System.IO.File.OpenRead(FileName)
Dim att As New DimeAttachment("application/dime", TypeFormat.Unknown,
sendFile)
ResponseSoapContext.Current.Attachments.Add(att)
End Sub

Client:

Private Sub SaveFile(ByVal att As System.IO.Stream)
Dim data() As Byte = ConvertStreamToByteBuffer(att)
If (System.IO.File.Exists(m_localFile)) Then
System.IO.File.Delete(m_localFile)
End If
Dim outFile As System.IO.FileStream
outFile = System.IO.File.OpenWrite(m_localFile)
outFile.Write(data, 0, data.Length)
outFile.Close()
End Sub

Private Function ConvertStreamToByteBuffer(ByVal theStream As
System.IO.Stream) As Byte()
If (theStream.Position > 0 And theStream.CanSeek) Then
theStream.Position = 0
End If
Dim oneByte As Integer
Dim tempStream As New System.IO.MemoryStream
While (oneByte = theStream.ReadByte() <> -1)
tempStream.WriteByte(CByte(oneByte))
End While

Return tempStream.ToArray()
End Function

Private Sub cmdCopyFile_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles cmdCopyFile.Click
Dim svc As MyDimeServiceWse = New MyDimeServiceWse
svc.CreateDimedApplication(m_serverFile)
If svc.ResponseSoapContext.Attachments.Count = 1 Then
SaveFile(svc.ResponseSoapContext.Attachments(0).Stream)
End If
End Sub
 

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

Members online

Forum statistics

Threads
473,982
Messages
2,570,186
Members
46,742
Latest member
AshliMayer

Latest Threads

Top