2011-04-18 125 views
4

我正嘗試以編程方式使用Azure Reporting Services呈現PDF。我懷疑實際的PDF檢索是好的,但我無法找到一種在請求報告(通過URL)之前驗證連接的方法。我正在使用Web應用程序的服務層,但無法使用Web引用(可能不適用於Azure),使用ReportViewer控件(因爲它是服務層方法)沒有意義。報告服務身份驗證問題

我有所有的細節連接,但我懷疑我需要一個cookie進行身份驗證,我不知道如何手動創建此。任何建議/解決方案?

這裏是我到目前爲止的代碼:

string userName = BJConfigurationManager.GetSetting("ReportingServiceUsername"); 
string password = BJConfigurationManager.GetSetting("ReportingServicePassword"); 
NetworkCredential networkCredential = new NetworkCredential(userName, password); 
Domain.Report report = GetReportById(id); 

int timeout = 30; //seconds 
string url = "https://bleh.ctp.reporting.database.windows.net/ReportServer/Pages/ReportViewer.aspx?..."; 
string destinationFileName = "@C:\\Temp.pdf"; 

// Create a web request to the URL 
HttpWebRequest MyRequest = (HttpWebRequest)WebRequest.Create(url); 
MyRequest.PreAuthenticate = true; 
MyRequest.Credentials = networkCredential; 
MyRequest.Timeout = timeout * 1000; 
try 
{ 
    // Get the web response -- THE RESPONSE COMES BACK AS UNAUTHENTICATED... 
    HttpWebResponse MyResponse = (HttpWebResponse)MyRequest.GetResponse(); 

回答

0

我不認爲這是去工作。 Azure報告使用表單身份驗證,據我所知,您將無法將Forms Auth cookie與MachineKey一起加密。

+3

那麼還有沒有其他的方法可以在沒有報告查看器的情況下在沒有引用報告服務的情況下檢索代碼中的pdf?當然,如果我有完整的URL,用戶名和密碼,肯定有辦法進行身份驗證。如果可以手動完成,那麼一定有辦法以編程方式完成它? – Chris 2011-04-18 14:36:29

0

我試圖完成相同的任務..但使用WebRequest是不可能的。 我改變使用ServerReport類這樣的方法:

ServerReport report; 
report = new ServerReport(); 
report.ReportServerUrl = new Uri(reportServerName + "/ReportServer"); 
report.ReportPath = "/ReportPath"; 
report.ReportServerCredentials = new ReportServerCredentials(); 
report.SetParameters(new Microsoft.Reporting.WebForms.ReportParameter("param1", param1)); 
report.SetParameters(new Microsoft.Reporting.WebForms.ReportParameter("param2", param1)); 
return report.Render(reportParams.OutputFormat); 

的ReportServerCredentials類必須實現像this的IReportServerCredentials接口。

有關IReportServerCredentials接口和實現的更多信息here