greetings and salutations, o smarter than i.
i've been working on a solution to secure the delivery of pdfs to client
browsers. we're introducing an public-website element, so i've decided to use
a webservice on the internal application webserver to pass a pdf as a byte
array to a public webserver outside the LAN, where it can be forwarded on the
response to the client browser.
i could use some advice how to improve this: i'm not entirely satisfied with
the memory useage--i'm trying to shy away from taking on making a ISAPI
extention if i can get this efficient enough as is.
more vexingly, every so often, a local user will experience an error where
the PDF is never saved/opened after they make their choice on the file
open/save dialog. further, msie's progress meter remains and looks like it's
very slowly filling (or timing out) even after the pdf has successfully been
saved/opened--is there a final signal i'm failing to send to the browser..?
I designed the web service as follows:
Public Class DocumentRequest
Inherits System.Web.Services.WebService
Private EXAMPLE_DIR As String =
Server.mappath("/ExportedPDFs/ExampleSheets/")
Private Function BinaryGetPDFDocument(ByVal FileDIR As String, ByVal
FileNum As String) As Byte()
Dim FileStreamIn As New System.IO.FileStream(FileDIR + FileNum +
".pdf", System.IO.FileMode.Open, System.IO.FileAccess.Read,
System.IO.FileShare.Read)
Dim PDFData(FileStreamIn.Length) As Byte
Dim i As Integer = FileStreamIn.Read(PDFData, 0,
CInt(FileStreamIn.Length))
While (i < CInt(FileStreamIn.Length))
System.Threading.Thread.Sleep(200)
End While
FileStreamIn.Close()
Return PDFData
End Function
Private Function CheckExistsPDFDocument(ByVal FileDIR As String, ByVal
FileNum As String) As Boolean
Try
If (System.IO.File.Exists(FileDIR + FileNum + ".pdf")) Then
Return True
Else
Return False
End If
Catch
Return False
End Try
End Function
<WebMethod()> _
Public Function GetExampleSheet(ByVal FileNum As String) As Byte()
Return BinaryGetPDFDocument(EXAMPLE_DIR, FileNum)
End Function
<WebMethod()> _
Public Function CheckExistsExampleSheet(ByVal FileNum As String) As
Boolean
Return CheckExistsPDFDocument(EXAMPLE_DIR, FileNum)
End Function
End Class
and i wrote a consume function as follows:
Friend Sub PushPDFtoClient(ByRef Response As System.Web.HttpResponse,
ByVal FileNum As String, ByVal TYPE As String)
Dim ws As New PDFRequest.DocumentRequest
Dim PDFData() As Byte
Try
If (TYPE = "EXAMPLE") Then
PDFData = ws.GetExampleSheet(FileNum)
End If
Catch ex As Exception
'EDITED - removed some private logging functions
Response.Write("<script language=""javascript""
type=""text/javascript"">alert('There was an unexpected error accessing the
PDF')</script>")
Exit Sub
End Try
Dim ms As System.IO.MemoryStream = New System.IO.MemoryStream(PDFData)
Response.Clear()
Response.ContentType = "application/octet-stream"
Response.AddHeader("Content-Disposition", "attachment; filename=" &
TYPE & "-" & FileNum & ".pdf; size=" & PDFData.Length.ToString)
Response.AddHeader("Content-Length", PDFData.Length.ToString)
Response.Flush()
Dim chunkSize As Integer = 1024
Dim i As Integer
For i = 0 To PDFData.Length Step chunkSize
If (Not Response.IsClientConnected) Then
Exit For
End If
Dim size As Integer = chunkSize
If (i + chunkSize >= PDFData.Length) Then
size = (PDFData.Length - i)
End
Dim chunk(size - 1) As Byte
ms.Read(chunk, 0, size)
Response.BinaryWrite(chunk)
Response.Flush()
Next
ms.Close()
Response.End()
End Sub 1 2521
First, you need to change your line...
Response.ContentType = "application/octet-stream"
..to...
Response.ContentType = "application/pdf"
Then, you have to actually write the byte array to the stream, like so...
Response.BinaryWrite(PDFData)
Then, you finish it off...
Response.Flush()
Response.Close()
If you still have problems, try changing the .AddHeader statement to read
'inline' instead of 'attachment'
"evilme" <ev****@discussions.microsoft.com> wrote in message
news:D7**********************************@microsof t.com... greetings and salutations, o smarter than i. i've been working on a solution to secure the delivery of pdfs to client browsers. we're introducing an public-website element, so i've decided to use a webservice on the internal application webserver to pass a pdf as a byte array to a public webserver outside the LAN, where it can be forwarded on the response to the client browser.
i could use some advice how to improve this: i'm not entirely satisfied with the memory useage--i'm trying to shy away from taking on making a ISAPI extention if i can get this efficient enough as is.
more vexingly, every so often, a local user will experience an error where the PDF is never saved/opened after they make their choice on the file open/save dialog. further, msie's progress meter remains and looks like it's very slowly filling (or timing out) even after the pdf has successfully been saved/opened--is there a final signal i'm failing to send to the browser..?
I designed the web service as follows:
Public Class DocumentRequest Inherits System.Web.Services.WebService
Private EXAMPLE_DIR As String = Server.mappath("/ExportedPDFs/ExampleSheets/")
Private Function BinaryGetPDFDocument(ByVal FileDIR As String, ByVal FileNum As String) As Byte() Dim FileStreamIn As New System.IO.FileStream(FileDIR + FileNum + ".pdf", System.IO.FileMode.Open, System.IO.FileAccess.Read, System.IO.FileShare.Read) Dim PDFData(FileStreamIn.Length) As Byte Dim i As Integer = FileStreamIn.Read(PDFData, 0, CInt(FileStreamIn.Length)) While (i < CInt(FileStreamIn.Length)) System.Threading.Thread.Sleep(200) End While FileStreamIn.Close() Return PDFData End Function
Private Function CheckExistsPDFDocument(ByVal FileDIR As String, ByVal FileNum As String) As Boolean Try If (System.IO.File.Exists(FileDIR + FileNum + ".pdf")) Then Return True Else Return False End If Catch Return False End Try End Function
<WebMethod()> _ Public Function GetExampleSheet(ByVal FileNum As String) As Byte() Return BinaryGetPDFDocument(EXAMPLE_DIR, FileNum) End Function
<WebMethod()> _ Public Function CheckExistsExampleSheet(ByVal FileNum As String) As Boolean Return CheckExistsPDFDocument(EXAMPLE_DIR, FileNum) End Function
End Class
and i wrote a consume function as follows:
Friend Sub PushPDFtoClient(ByRef Response As System.Web.HttpResponse, ByVal FileNum As String, ByVal TYPE As String) Dim ws As New PDFRequest.DocumentRequest Dim PDFData() As Byte
Try If (TYPE = "EXAMPLE") Then PDFData = ws.GetExampleSheet(FileNum) End If Catch ex As Exception 'EDITED - removed some private logging functions Response.Write("<script language=""javascript"" type=""text/javascript"">alert('There was an unexpected error accessing the PDF')</script>") Exit Sub End Try
Dim ms As System.IO.MemoryStream = New System.IO.MemoryStream(PDFData) Response.Clear() Response.ContentType = "application/octet-stream" Response.AddHeader("Content-Disposition", "attachment; filename=" & TYPE & "-" & FileNum & ".pdf; size=" & PDFData.Length.ToString) Response.AddHeader("Content-Length", PDFData.Length.ToString) Response.Flush()
Dim chunkSize As Integer = 1024 Dim i As Integer For i = 0 To PDFData.Length Step chunkSize
If (Not Response.IsClientConnected) Then Exit For End If
Dim size As Integer = chunkSize If (i + chunkSize >= PDFData.Length) Then size = (PDFData.Length - i) End
Dim chunk(size - 1) As Byte ms.Read(chunk, 0, size) Response.BinaryWrite(chunk) Response.Flush() Next ms.Close() Response.End() End Sub This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Doug Farrell |
last post by:
Hi everyone,
I'm trying to build a program to interface to a SOAP/XML interface
provided by one of our vendors. This interface is built with MS SOAP
Toolkit 3.0, so I'm guessig they are running...
|
by: turnit \(removethis\) |
last post by:
I have a login form that uses the post method to carry the
information to the next page. The form works just fine in
ie6.0, but fails in mozilla and fails in ie5.2 on a
mac. "HTTP/1.1 400 Bad...
|
by: Kevin C |
last post by:
When designing an asynchronous service-based system, generally speaking
whose responsibility is it to determine when a duplicate request is sent -
the system hosting the service or the feeding...
|
by: Matt |
last post by:
Hello all,
We are using Forms Authentication in an application to protect both
sensitive ASP.Net pages and Web services.
This question is relating to Web services and forms authentication,...
|
by: CG |
last post by:
I have a VS .NET 2003 web service project which references a Managed
C++ assembly.
The managed C++ assembly in turn uses some unmanaged code.
Because of some restriction in the unmanaged...
|
by: Codex Twin |
last post by:
Hello
apologies if this is the wrong newsgroup to be sending this to.
Basically, I have an ASP.NET application that I am trying to force to use a
proxy server settings. This can be done by...
|
by: Jit Prasad |
last post by:
I have a working client-side Vb.Net (.net v1.0) app that talks to a Webspere
webservice on a windows 2000 server. The client side app runs on a citrix
server, also a Windows 2000 server. The app...
|
by: jctwguy |
last post by:
G'day all
My pc is on a domain and I have a test server in a work group. all the web
application and the web service are working fine locally, but when I copy the
project using service extension...
|
by: Tim Reynolds |
last post by:
Our .Net application calls a web method of aplpication 2 that resides on
their Apache server. When I as a developer C#, Studios 2003, make the call to
their web method from my desktop, I receive no...
|
by: Gibble |
last post by:
Hi,
We have a javascript on a page that calls a .NET web service. Oddly,
in our web servers event logs the following errors kept repeating
every minute (that made sense since the web service...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
| |