• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 290
  • Last Modified:

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

Hi,
 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.

Thanks

K
0
Khaki
Asked:
Khaki
1 Solution
 
samittCommented:
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
        Try

            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"



            Try

                mywriter = New StreamWriter(bojRequest.GetRequestStream())

                input = strRead.ReadLine
                While Not input Is Nothing

                    mywriter.Write(input)
                    input = strRead.ReadLine

                End While

                'mywriter.Write(input)


                mywriter.Close()

            Catch ex As Exception

                MsgBox(ex.Message())

            End Try

            Dim objResponse As HttpWebResponse = bojRequest.GetResponse()

            Dim sr As StreamReader


            sr = New StreamReader(objResponse.GetResponseStream())

            result = sr.ReadToEnd

            MsgBox(result)

        Catch ex As Exception

            MsgBox(ex.Message())

        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

        Response.Write(strmContents)





    End Sub
0
 
KhakiAuthor Commented:
thanks, that is one solution, but I found another solution using DIME
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now