Web Service?

Discussion in 'ASP .Net' started by Charles A. Lackman, Jul 13, 2004.

  1. Hello,

    Is there a way to Write a file to a stream using a web service? If so How?

    Any Help or Suggestions will be greatly appreciated.

    Thanks,
    Chuck
    Charles A. Lackman, Jul 13, 2004
    #1
    1. Advertising

  2. This is a webmethod that takes a file and convert it back out to a Binary Stream

    <WebMethod()> _
    Public Function ReadFileToStream() As Byte()
    Dim fs As FileStream

    Try
    ' Read file and return contents
    Dim serverPath As String = "C:\Inetpub\wwwroot\postinfo.html"
    fs = File.Open(serverPath, FileMode.Open, FileAccess.Read)

    Dim lngLen As Long = fs.Length
    Dim abytBuffer(CInt(lngLen - 1)) As Byte
    fs.Read(abytBuffer, 0, CInt(lngLen))
    Return abytBuffer

    Finally
    ' Make sure that file stream is
    ' closed even if an error occurs.
    fs.Close()
    End Try
    End Function

    Hope this helps

    "Charles A. Lackman" wrote:

    > Hello,
    >
    > Is there a way to Write a file to a stream using a web service? If so How?
    >
    > Any Help or Suggestions will be greatly appreciated.
    >
    > Thanks,
    > Chuck
    >
    >
    >
    =?Utf-8?B?VGFtcGEgLk5FVCBLb2Rlcg==?=, Jul 13, 2004
    #2
    1. Advertising

  3. Hello and Thank you for your response,

    I have noticed that when this code is implemented it does not cause the
    client computer to open a download dialogbox. I am assuming that I have to
    implement code to receive the file then write it to the clients computer.
    Is this correct. The Web Service is being called from a Desktop
    Application. I am having a struggle trying to implement this.

    Client Computer (Desktop Computer)

    fs = New IO.FileStream("C:\Me.wma", IO.FileMode.Create, IO.FileAccess.Write)
    Dim BW As New IO.BinaryWriter(fs)
    Dim leng As Integer = fs.Length
    Dim abytBuffer(CInt(leng - 1)) As Byte
    fs.Write(abytBuffer, 0, CInt(leng))
    ' This causes the file to be 0 in length


    Dim serverPath As String = "C:\Test1.WMA"
    fs = New IO.FileStream(TheService.StartDownload, IO.FileMode.OpenOrCreate)
    Dim BW As New IO.BinaryWriter(fs)
    Dim AByte() As Byte = TheService.StartDownload() 'Your Code implemented on
    the service
    Dim AByte1 As Byte
    For Each AByte1 In AByte
    bw.write(Abyte1)
    next
    'This Causes the File to write Gigs and Gigs of data to the file Test1.WMA

    Thanks again for your assistance,
    Chuck
    Charles A. Lackman, Jul 13, 2004
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. hocho888
    Replies:
    1
    Views:
    600
  2. Michael Averstegge
    Replies:
    0
    Views:
    4,188
    Michael Averstegge
    Jan 10, 2006
  3. Not Me
    Replies:
    1
    Views:
    3,163
    Not Me
    Jun 5, 2007
  4. Isaias Formacio Serna

    Web Service that calls an external Web Service

    Isaias Formacio Serna, Jan 28, 2004, in forum: ASP .Net Security
    Replies:
    5
    Views:
    232
  5. Leo Violette
    Replies:
    0
    Views:
    990
    Leo Violette
    Apr 17, 2009
Loading...

Share This Page