我制作了一个 SSRS Bulk 报告器,它使用 HTTPWebRequest 和 HTTPWebResponse 从 SSRS 查询报告,以获取流并将其作为文件保存为 PDF。
但是,客户抱怨说这需要很长时间。我已经测试过了,这个功能需要 +- 15.5 秒。如果我在 GetResponseStream 和文件编写器之间设置一个中断,并且在进入下一部分之前等待大约 3 秒,它会减少 4 秒的总时间吗?
任何人都可以解释这一点/或提供一些建议以使其更快一点吗?
这是功能:
Public Function ExportReport(ByVal QueryStringParameters As String, ByVal FileName As String) As String
Dim PDFName As String = ReportFolderPath & FileName & ".pdf"
'Create a http request or connecting to the report server.
Dim ReportHTTPRequest As HttpWebRequest = Nothing
'Create a http response to catch the data stream returned from the http request.
Dim ReportHTTPResponse As HttpWebResponse = Nothing
'Create a stream to read the binary data from the http reponse.
Dim ReportStream As Stream = Nothing
Dim ReportFileStream As FileStream = Nothing
'Create an array of bytes to get the binary data from the stream.
Dim ReportBytes As Byte()
Dim ReportBuffer As Integer = 204800
Dim ReportBytesRead As Integer = 0
'Create a webrequest to get the report with all the report parameters included.
ReportHTTPRequest = WebRequest.Create(ReportServerURL & QueryStringParameters)
ReportHTTPRequest.Credentials = CredentialCache.DefaultCredentials
'Get the response from the request.
ReportHTTPResponse = ReportHTTPRequest.GetResponse()
'Read the binary stream from the http response.
ReportStream = ReportHTTPResponse.GetResponseStream()
ReportBytes = New Byte(ReportBuffer) {}
ReportBytesRead = ReportStream.Read(ReportBytes, 0, ReportBuffer)
ReportFileStream = New FileStream(PDFName, FileMode.Create)
Do While ReportStream.CanRead And ReportBytesRead > 0
ReportFileStream.Write(ReportBytes, 0, ReportBytesRead)
ReportBytesRead = ReportStream.Read(ReportBytes, 0, ReportBuffer)
Loop
ReportHTTPResponse.Close()
ReportStream.Close()
ReportFileStream.Close()
Return PDFName
End Function