报告服务身份验证问题
问题描述:
我正尝试以编程方式使用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();
答
我不认为这是去工作。 Azure报告使用表单身份验证,据我所知,您将无法将Forms Auth cookie与MachineKey一起加密。
答
查看标题为“SOAP Management Endpoint Programmatic Access”的部分: http://msdn.microsoft.com/en-us/library/windowsazure/771e88b6-ab0f-4910-a5fa-5facd8d56767#SOAPManagement。 它解释了如何在没有ReportViewer控件的情况下使用cookie容器进行身份验证。
答
我试图完成相同的任务..但使用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。
那么还有没有其他的方法可以在没有报告查看器的情况下在没有引用报告服务的情况下检索代码中的pdf?当然,如果我有完整的URL,用户名和密码,肯定有办法进行身份验证。如果可以手动完成,那么一定有办法以编程方式完成它? – Chris 2011-04-18 14:36:29