Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: ASP.NETVB.NET
Okay, I'm working with a Bing Ads API/Service and I'm trying to pull data from a report. I'm using HTTPS to retrieve the data as I have to send a username and password along with some parameters. If I save the response as a file, it converts the data correctly. What I'm trying to do is read the data into a memory stream and pull out the pieces I want from there and then save to our database.
 
When I try to read the binary data into a memory stream I get either an empty string or the following characters "PK . There's some other characters not pasting in one being a paragraph symbol. Sometimes I can get a whole screen of garbleygook characters that convert to the above characters when I try to copy paste them. I think I'm not converting the binary string correctly.
 
Below is the code that I'm using to retrieve the data and convert to a string at this point.
 
' Open a connection to the URL where the report is available.
Dim webRequest As HttpWebRequest = Net.WebRequest.Create _(statusResponse.ReportRequestStatus.ReportDownloadUrl)
Dim response = CType(webRequest.GetResponse, HttpWebResponse)
Dim httpStream = response.GetResponseStream
 
' Open the destination file.
Dim zipFileInfo = New FileInfo(zipFileName)
 
If Not zipFileInfo.Directory.Exists Then
    zipFileInfo.Directory.Create()
End If
 
Dim fileStream = New FileStream(zipFileInfo.FullName, FileMode.Create)
Dim ms = New MemoryStream
Dim binaryWriter = New BinaryWriter(FileStream)
Dim binWriter = New BinaryWriter(ms)
Dim binaryReader = New BinaryReader(httpStream)
 
Try
    ' Read the report, and then write it to the destination file.
    Dim bufferSize As Integer = 100000
 
    While True
        ' Read the report data.
        Dim buffer() = binaryReader.ReadBytes(bufferSize)
 
        ' Write the report data to the destination file.
        binaryWriter.Write(buffer)
        binWriter.Write(buffer)
 
        Console.WriteLine(buffer.Length)
 
        ' If the end of the report is reached, break out of the
        ' loop.
        If (buffer.Length <> bufferSize) Then
            Exit While
        End If
 
    End While
Finally
    ' Clean up.
    binaryWriter.Close()
    binaryReader.Close()
    fileStream.Close()
    httpStream.Close()
End Try
 
Dim reader As New StreamReader(ms, System.Text.Encoding.UTF8)
Dim xmlString As String = reader.ReadToEnd()
Console.WriteLine(xmlString) 'just using this to see what is in the string
 

Can anyone give me some pointers on what isn't correct about this? I've tried goggling about memorystreams and haven't found anything that is making a difference.
 
Thanks,
Carolyn
Posted 4-Jan-13 6:53am
CARisk3973
Comments
ChrisTopherus at 4-Jan-13 13:15pm
   
i can only give you a hint. in wcf, you can declare a request- and a responseformat. maybe there is something like that for your snippet...

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Okay. Got this figured out. The http response was not in xml as I thought but was a zipped file. By using DotNetZip, I was able to read the http response into an memory stream and convert that to the xml document all while in memory.
 
Thanks,
 
Carolyn
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 529
1 OriginalGriff 307
2 Damith Weerasinghe 295
3 ravikhoda 260
4 Tadit Dash 180
0 Sergey Alexandrovich Kryukov 10,974
1 OriginalGriff 6,667
2 Peter Leow 4,760
3 Abhinav S 3,813
4 Maciej Los 3,565


Advertise | Privacy | Mobile
Web04 | 2.8.140421.2 | Last Updated 7 Jan 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Use
Layout: fixed | fluid