Programowanie pod Reporting Services można wykonać na co najmniej 2 sposoby:
- Wykorzystując WebService i w ten sposób możesz na Reporting Services zrobić praktycznie wszystko np. uruchomić raport lub zarządzać raportami
- Wykorzystując kontrolki służące do uruchomienia i zaprezentowania raportu.
- Wykorzystując pisane ręcznie adresy URL wskazujące na Report Server, które poprzez QueryString określają jaki raport ma być uruchomiony (metoda GET)
- Wykorzystując nawet ręcznie tworzone formularze przesyłając do Reporting Services wartości w parametrach metodą POST
- …
Skupmy się na razie na Web Service. Jeśli mowa o SQL 2008 i trybie native dla Reporting Services, to mamy 2 Web Service:
- ReportExecution2005 – do uruchamiania raportów
- ReportService2005 – do zarządzania raportami
Załóżmy, że masz do napisania aplikację, która ma wyciągnąć z serwera dany raport w postaci Excel. W tym przypadku należy skorzystać z Web Service ReportExecution2005.
Po pierwsze dodaj w swoim projekcie referencję do tego Web Service:
- Na projekcie kliknij prawym przyciskiem myszy i wybierz Add Service Reference
- Kliknij Advanced
- Kliknij Add Web Reference
- Podaj adres URL: http://localhost/ReportServer/ReportExecution2005.asmx (localhost zamień u siebie na nazwę serwera, na którym działa Reporting Services)
- Zmień nazwę (u mnie RS2005) i kliknij Add Reference
Od tej pory do zdanych usług Reporting Services możesz sięgać przy pomocy lokalnej klasy proxy o nazwie RS2005.
Pora więc na stworzenie programu. Umieść na formularzu kontrolkę buton i oprogramuj kliknięcie tego przycisku:
1 |
protected void Button1_Click(object sender, EventArgs e) |
1 |
{ |
1 |
RS2005.ReportExecutionService rs = new RS2005.ReportExecutionService(); |
1 |
rs.Credentials = System.Net.CredentialCache.DefaultCredentials; |
1 |
byte[] result = null; |
1 |
//Left all spaces ors slashes |
1 |
string reportPath = "/TestReportAW/Report1"; |
1 |
string format = "EXCEL"; |
1 |
string historyid=null; |
1 |
string encoding; |
1 |
string mimetype; |
1 |
string extension; |
1 |
RS2005.Warning[] warning = null; |
1 |
string[] streamIDs = null; |
1 |
RS2005.ExecutionInfo execInfo = new RS2005.ExecutionInfo(); |
1 |
RS2005.ExecutionHeader execHeader = new RS2005.ExecutionHeader(); |
1 |
rs.ExecutionHeaderValue = execHeader; |
1 |
execInfo = rs.LoadReport(reportPath, historyid); |
1 |
String sessionId = rs.ExecutionHeaderValue.ExecutionID; |
1 2 |
result = rs.Render(format, null, out extension, out encoding, out mimetype, out warning, out streamIDs); |
1 |
System.IO.File.WriteAllBytes(@"c:\temp\report.xls", result); |
1 |
} |
Poczytaj więcej: http://support.microsoft.com/kb/875447