Il a été un moment que je l'ai fait ce code, mais il peut aider: votre projet web doit être un site Web, et pas un projet de type "Application Web ASP.Net", ou vous ne serez pas en mesure d'ajouter la référence mentionnée ci-dessous. Faites un clic droit sur le projet et ajoutez un dossier ASP.Net - App_WebReferences. Vous devrez spécifier le serveur où votre SRS est; choisissez le .asmx. Une fois ajouté, le dossier sous ce niveau s'appelle RSService, et sous cela se trouvent 2 choses: reportservice.discomap & .wsdl. Dans mon VB, je les importations RSService et importations System.Web.Services.Protocols, puis ...
Dim MyRS As New ReportingService
Le service de reporting est sur un autre serveur que le serveur Web de l'application est, donc je peux » t procédez comme suit: MyRS.Credentials = System.Net.CredentialCache.DefaultCredentials
au lieu de cela:. MyRS.Credentials = New System.Net.NetworkCredential(rs1, rs2, rs3)
, où le RS1/2/3 sont connexion à la boîte SRS, mot de passe à la boîte SRS, & nom de domaine »(. Ceux-ci sont cryptées dans mon web.config)
Ensuite, une pâte de masse:
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
Que faire si je n'utilise pas les rapports locaux mais que je ne veux pas laisser de valeurs explicites sur l'url? – Leonardo