Nó được một lúc kể từ khi tôi đã làm mã này, nhưng nó có thể giúp: dự án web của bạn có phải là một trang web, và không phải là một dự án kiểu "ASP.Net Web Application", hoặc bạn sẽ không thể thêm tham chiếu được đề cập dưới đây. Nhấp chuột phải vào dự án và thêm một thư mục ASP.Net - App_WebReferences. Bạn sẽ phải chỉ định máy chủ nơi SRS của bạn là; chọn .asmx. Sau khi được thêm, thư mục dưới cấp đó được gọi là RSService và dưới đây là 2 điều: reportservice.discomap & .wsdl. Trong VB của tôi, tôi làm Imports RSService và nhập khẩu System.Web.Services.Protocols, sau đó ...
Dim MyRS As New ReportingService
Dịch vụ báo cáo trên một máy chủ khác với máy chủ web ứng dụng được bật, vì vậy tôi có thể' t làm như sau: MyRS.Credentials = System.Net.CredentialCache.DefaultCredentials
Thay vào đó:. MyRS.Credentials = New System.Net.NetworkCredential(rs1, rs2, rs3)
, nơi RS1/2/3 là đăng nhập để SRS hộp, mật khẩu để SRS hộp, & tên miền"(. đây là những mã hóa trong web.config của tôi)
Sau đó, khối lượng dán:
MyRS.Credentials = New System.Net.NetworkCredential(rs1, rs2, rs3)
Dim ReportByteArray As Byte() = Nothing
Dim ReportPath As String = "/SRSSiteSubFolder/ReportNameWithoutRDLExtension"
Dim ReportFormat As String = "PDF"
Dim HistoryID As String = Nothing
Dim DevInfo As String = "<DeviceInfo><Toolbar>False</Toolbar></DeviceInfo>"
'Dim x As ReportParameter - not necessary
Dim ReportParams(0) As ParameterValue
ReportParams(0) = New ParameterValue()
ReportParams(0).Name = "TheParamName"
ReportParams(0).Value = WhateverValue
Dim Credentials As DataSourceCredentials() = Nothing
Dim ShowHideToggle As String = Nothing
Dim Encoding As String
Dim MimeType As String
Dim ReportHistoryParameters As ParameterValue() = Nothing
Dim Warnings As Warning() = Nothing
Dim StreamIDs As String() = Nothing
'Dim sh As New SessionHeader() - not necessary
''MyRS.SessionHeaderValue = sh - not necessary
ReportByteArray = MyRS.Render(ReportPath, ReportFormat, HistoryID, DevInfo, ReportParams, Credentials, _
ShowHideToggle, Encoding, MimeType, ReportHistoryParameters, Warnings, StreamIDs)
'(Yay! That line was giving "HTTP error 401 - Unauthorized", until I set the credentials
' as above, as explained by http://www.odetocode.com/Articles/216.aspx.)
'Write the contents of the report to a PDF file:
Dim fs As FileStream = File.Create(FullReportPath, ReportByteArray.Length)
fs.Write(ReportByteArray, 0, ReportByteArray.Length)
fs.Close()
Call EmailTheReport(FullReportPath)
If IO.File.Exists(FullReportPath) Then
IO.File.Delete(FullReportPath)
End If
nếu im không sử dụng báo cáo địa phương nhưng không muốn để lại giá trị rõ ràng trên url? – Leonardo