Visual Basic Response.BinaryWrite to finish in the OutputStream

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Paul Klingele
    New Member
    • Jul 2010
    • 2

    Visual Basic Response.BinaryWrite to finish in the OutputStream

    I am using Visual Basic to dynamically create a Visio diagram. It is called from a web application.

    The web app makes the call to the .aspx file, which does its work and then writes the file to the web app through Response.Binary Write.

    The problem is this: there could be multiple users on the web app, and the VB app is currently confusing the web app with simultaneous use. That is, if two users both make a call to the VB app, the VB app doesn't separate the output, so one user gets a binary file (unreadable by Visio) with both users' contents, and the other user gets a blank Visio file.

    Can I use anything in the Response.AddHea der to distinguish the output so the Java code for the app can pick the correct output?
  • Joseph Martell
    Recognized Expert New Member
    • Jan 2010
    • 198

    #2
    I'm not sure I completely understand your scenario, but if you are just looking for a unique token to pass through your processing for each call then you could try using a GUID.

    Comment

    • Paul Klingele
      New Member
      • Jul 2010
      • 2

      #3
      Originally posted by jbm1313
      I'm not sure I completely understand your scenario, but if you are just looking for a unique token to pass through your processing for each call then you could try using a GUID.
      User A and User B both click a link in a web app. The link is dynamically generated in the form of:



      A java class in the web app creates a java.net.URLCon nection with the url from the link. Then, it creates a BufferedInputSt ream object to read the response from the VB app.

      The VB app creates a FileData.vb object:

      Code:
      Public Class FileData
          Private _name As String
          Private _mimeType As String
          Private _data As Byte()
      
          Public Property Name() As String
              Get
                  Return _name
              End Get
              Set(ByVal Value As String)
                  _name = Value
              End Set
          End Property
      
          Public Property MimeType() As String
              Get
                  Return _mimeType
              End Get
              Set(ByVal Value As String)
                  _mimeType = Value
              End Set
          End Property
      
          Public Property Data() As Byte()
              Get
                  Return _data
              End Get
              Set(ByVal Value As Byte())
                  _data = Value
              End Set
          End Property
      
      End Class
      Then, it reads from a database prompted by the "PID" query string, and creates a Visio diagram that is assigned as an array of bytes in a FileData object named diagrams.

      Code:
              Dim diagrams() As FileData
      
              diagrams = Diagram.Request(intPID, intLID, Not boolGetPdf, boolGetPdf, True, namesExist)
      
              If diagrams.Length > 0 And Response.IsClientConnected Then
       
                  If boolGetPdf Then
                      Response.ContentType = "application/pdf"
                  Else
                      Response.ContentType = "application/x-visio"
                  End If
      
                  Response.AppendHeader("Content-Disposition", "attachment; filename=""" & diagrams(0).Name & """")
                  Response.AppendHeader("Content-Length", "" & diagrams(0).Data.GetLength(0))     ' Set content length
      
                  Response.BinaryWrite(diagrams(0).Data)
              Else
                  ' Nothing To Do
                  Response.Write("No data returned from request")
              End If
      
              Response.Flush()
              Response.End()
      The VB app creates two instances of Visio.exe, 1 for A and 1 for B.

      The VB app then writes this back to the java class that called the URLConnection. The java class reads the byte data from the BufferedInputSt ream, and writes it to the response of the web app with response.getOut putStream().wri te(data, 0, length), where data is an array of bytes (byte[]) and length is the return value of BufferedInputSt ream.read(data) .

      Whoever is "done" first and clicks on the "Open/Save" dialog box first gets a binary file that is twice as big as it's supposed to be that cannot be opened by Visio, and the loser gets a blank Visio document.

      I have been researching, reading, and studying some way to make one of these two processes more choosy. Ideally, the java class would only accept byte data in the output stream from the "correct" source, but how does the VB app distinguish the byte data in the OutputStream? I would think that Response.Binary Write would be unique to a specific http response, instead of just dumping it to one static outputstream that's available to anyone listening/requesting.

      Any help or insight is appreciated!

      Comment

      Working...