How to stream large amount of data from windows service to web service?

 I am writing both the windows service and the web service.
 The windows service is supposed to transfer a large amount of data to the web service.   I would like to stream data if possible.  How can I do this?  
Both services will be written in VB.NET.


Who is Participating?
samittConnect With a Mentor Commented:
With an HTTP Post you could stream upto 1 GB of data. Here's an example
/********************Windows Service**************************/
  Private Sub btnPost_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPost.Click

        Dim xDoc = New XmlDocument

        Dim mywriter As StreamWriter

            Dim input, ip As String
            Dim s_strURL As String
            Dim strRead As StreamReader = File.OpenText("C:\ABC.txt")
            Dim strR As StreamReader = File.OpenText("C:\ABC.txt")

            s_strURL = "http://........./WebForm1.aspx"

            Dim bojRequest As HttpWebRequest = WebRequest.Create(s_strURL)

            bojRequest.Method = "POST"

            'input = strRead.ReadToEnd
            ip = strR.ReadToEnd

            bojRequest.ContentLength = ip.Length

            bojRequest.ContentType = "text/text"


                mywriter = New StreamWriter(bojRequest.GetRequestStream())

                input = strRead.ReadLine
                While Not input Is Nothing

                    input = strRead.ReadLine

                End While



            Catch ex As Exception


            End Try

            Dim objResponse As HttpWebResponse = bojRequest.GetResponse()

            Dim sr As StreamReader

            sr = New StreamReader(objResponse.GetResponseStream())

            result = sr.ReadToEnd


        Catch ex As Exception


        End Try

    End Sub

/******************Web Form (or Service)*************************/

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        'Put user code to initialize the page here

        ''Response.Write(Request.Files.Count & ": Files Received")

        Dim str As Stream, strmContents As String
        Dim counter, strLen, strRead As Integer

        str = Request.InputStream

        strLen = CInt(str.Length)

        Dim strArr(strLen) As Byte

        strRead = str.Read(strArr, 0, strLen)

        For counter = 0 To strLen - 1
            strmContents = strmContents & Chr(strArr(counter).ToString)
        Next counter


    End Sub
KhakiAuthor Commented:
thanks, that is one solution, but I found another solution using DIME
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.