Why custominize report can't generated PDF file on cutomnize page? RRS feed

  • Question

  • Hi, guys.
    I develop a SSRS on deploy on mscrm 4.0, publish it for external use.
    And i develop some plugin page for mscrm. I generate a pdf from my page in crm by SSRS.
    When the ReportingService2005 and ReportExecutionService2005 use DefaultCredentials, it will raise exception when LoadReport.
    But it's ok if i assign a user to ReportingService2005 and ReportExecutionService2005.

    The CRM Application is installed on Server A, when SQL Server and SSRS Server is installed on Server B. SQL version is SQL 2005.
    The exception message is :The request failed with HTTP status 401: Unauthorized 

    • Edited by Sea Water Friday, September 18, 2009 3:37 AM
    Friday, September 18, 2009 3:27 AM


All replies

  • This is the code

                System.Net.NetworkCredential credentials = new System.Net.NetworkCredential(UserId, Password, Domain);
                ReportingService2005 rs2005 = new ReportingService2005();
                ReportExecutionService re2005 = new ReportExecutionService();
                rs2005.Credentials =  CredentialCache.DefaultCredentials;//credentials; it's ok if i use credntials.
                re2005.Credentials = CredentialCache.DefaultCredentials;//credentials; it's ok if i use credntials.
                rs2005.Url =  "http://reportserverIP/reportserver/ReportService2005.asmx";
                re2005.Url = "http://reportserverIP/reportserver/ReportExecution2005.asmx";

                //prepare render arguments
                string historyID = null;
                string deviceinfo = null;
                string[] streamIDs = null;
                byte[] bytArray = null;
                string encoding = string.Empty;
                string mimeType = string.Empty;
                string extension = string.Empty;
                WSL.AWB.ReportExecution.Warning[] warnings = null;

                //define variables needed for GetParameters() method
                //get the report name
                string _reportname = reportPath;
                string _historyID = null;
                bool _forRendering = false;

                WSL.AWB.ReportService.ParameterValue[] _values = null;
                WSL.AWB.ReportService.DataSourceCredentials[] _credentials = null;
                WSL.AWB.ReportService.ReportParameter[] _parameters = null;
                //e. Load the SSRS report using ReportExecution2005

    // if ReportingService2005  use DefaultCredentials, there will generate excetion: The request failed with HTTP status 401: Unauthorized 
                WSL.AWB.ReportExecution.ExecutionInfo ei = re2005.LoadReport(reportPath, historyID);       

                //f. Get SSRS reportparameters
                //using ReportService2005 get the total parameters in the report
                //using ReportExecution2005 set the appropriate parameters value to render the report .

                //Get the no. of parameters in the report.
                _parameters = rs2005.GetReportParameters(_reportname, _historyID, _forRendering, _values, _credentials);
                int totalParams = _parameters.Length;

                //prepare report parameters
                WSL.AWB.ReportExecution.ParameterValue[] parameters = null;
                parameters = new WSL.AWB.ReportExecution.ParameterValue[totalParams];

                foreach (KeyValuePair<string, string> paramenter in reportParameters)
                    string ParaName = paramenter.Key;
                    for (int ix = 0; ix < totalParams; ix++)
                        if (ParaName == _parameters[ix].Name)
                            parameters[ix] = new WSL.AWB.ReportExecution.ParameterValue();
                            parameters[ix].Name = ParaName;
                            parameters[ix].Value = paramenter.Value;

                re2005.SetExecutionParameters(parameters, "en-us");

                //h. Render the report to get the specific format in byteArray format.
                bytArray = re2005.Render(format, deviceinfo
                    , out extension, out encoding, out mimeType
                    , out warnings, out streamIDs

                string reportname = reportPath.Substring(reportPath.LastIndexOf("/") + 1);
                string filename = reportname + "." + extension;

    Friday, September 18, 2009 3:36 AM