SSRS Web服务呈现报告HTTP 503服务器错误

时间:2016-10-05 09:20:46

标签: c# reporting-services

大家好日子。我尝试使用带有此类代码的ssrs Web服务。

using System.Collections.Generic;
using System.Linq;
using SSRS = ReportConnector.SSRS;
using SSRSExec = ReportConnector.SSRSExec;
using System.Net;

namespace ReportSoapConnection
{
    public static class ReportRunner
    {
        public static byte[] Report(string serverName, string reportLocation, NetworkCredential aCred, string aConnection, string reportformat, Dictionary<string, string> ReportParams)
        {
            SSRS.ReportingService2010 rptService = new SSRS.ReportingService2010();
            SSRSExec.ReportExecutionService rptExecute = new SSRSExec.ReportExecutionService();
            try
            {
                rptService.Url = serverName + "/ReportServer/ReportService2010.asmx";
                rptExecute.Url = serverName + "/ReportServer/ReportExecution2005.asmx";

                rptService.Credentials = aCred;
                rptService.Timeout = 3000000;
                rptExecute.Credentials = aCred;
                rptExecute.Timeout = 3000000;

                SSRSExec.ExecutionInfo execInfo = rptExecute.LoadReport(reportLocation, null);

                byte[] reportBytes = null;
                try
                {
                    SSRS.ItemParameter[] itemparams = rptService.GetItemParameters(reportLocation, null, true, null, null);
                    SSRSExec.ParameterValue[] execParameterValues = new SSRSExec.ParameterValue[itemparams.Count()];
                    int paramIndex = 0;
                    if (itemparams != null)
                    {
                        foreach (var rp in itemparams)
                        {
                            SSRSExec.ParameterValue assignThis = new SSRSExec.ParameterValue();
                            assignThis.Label = rp.Name;
                            assignThis.Name = rp.Name;
                            if (ReportParams.ContainsKey(rp.Name))
                                assignThis.Value = ReportParams[rp.Name];
                            else 
                            {
                                assignThis.Value = null;
                            }
                            execParameterValues[paramIndex++] = assignThis;
                        }
                        rptExecute.SetExecutionParameters(execParameterValues, "ru-Ru");
                    }
                    string mimeType;
                    string extention;
                    string[] streamIDs;
                    string encoding;
                    SSRSExec.Warning[] warnings;
                    reportBytes = rptExecute.Render(reportformat,   // report output format
                                                            null,
                                                            out extention,
                                                            out mimeType,
                                                            out encoding,
                                                            out warnings,
                                                            out streamIDs);
                }
                finally
                {
                }
                return reportBytes;
            }
            //  throw new Exception(string.Format("{0}, Server {1}, RL = {2} Source = {3} TargetSite = {4} ST = {5}", E.Message, serverName, reportLocation, E.Source, E.TargetSite, E.StackTrace), E);
            finally
            {
                rptService.Dispose();
                rptExecute.Dispose();
            }
        }
    }
}

class Program
{


    static void Main(string[] args)
    {
        Thread th = null;
        for (int i=0; i< 50; i++)
        {
            th = new Thread(Run);
            th.Start();
        }
        Console.WriteLine();
        Console.WriteLine("Press <ENTER> to terminate client.");
        Console.ReadKey();
    }

    static void Run()
    {
        ReportRunner.Report("http://srv-test", "/Dx/Reports/Cln/Inventory",
            new NetworkCredential("user", "pwd", "VC"), null, "PDF",
            new Dictionary<string, string> { { "FId", "1" }, { "Report_Id", "24921" }, { "Date", "2016-10-04" } });
    }
}

rptExecute.Render - 抛出异常 System.Web.Services.dll中发生了未处理的“System.Net.WebException”类型异常  HTTP 503:服务器错误。

如果我不使用多线程,那么好吧。我做错了什么? 谢谢你的帮助。

1 个答案:

答案 0 :(得分:2)

更改 rsreportserver.config 中的以下键值以执行并发请求。

默认值为20

<Add Key="MaxActiveReqForOneUser" Value="20"/>