Solved

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

Posted on 2004-09-15
2
272 Views
Last Modified: 2012-05-05
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
Comment
Question by:Khaki
2 Comments
 

Accepted Solution

by:
samitt earned 150 total points
ID: 12105855
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
 

Author Comment

by:Khaki
ID: 12120323
thanks, that is one solution, but I found another solution using DIME
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Well, all of us have seen the multiple EXCEL.EXE's in task manager that won't die even if you call the .close, .dispose methods. Try this method to kill any excels in memory. You can copy the kill function to create a check function and replace the …
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

757 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now