0

我已經做了一個SSRS批量報告,它使用HTTPWebRequest和HTTPWebResponse從SSRS查詢報告以獲取流並將其保存爲PDF文件。將GetResponseStream寫入文件需要很長的時間

然而,客戶抱怨說這需要很長時間。我已經測試過了,這個函數的時間是+ - 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 

回答

0

爲我工作一個神奇的東西,嘗試的32768

緩衝區大小
相關問題