C# SSRS Web服务呈现报告HTTP 503服务器错误
大家好。我尝试将SSRSWeb服务与这样的代码一起使用C# SSRS Web服务呈现报告HTTP 503服务器错误,c#,reporting-services,C#,Reporting Services,大家好。我尝试将SSRSWeb服务与这样的代码一起使用 using System.Collections.Generic; using System.Linq; using SSRS = ReportConnector.SSRS; using SSRSExec = ReportConnector.SSRSExec; using System.Net; namespace ReportSoapConnection { public static class ReportRunner
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" } });
}
}
使用System.Collections.Generic;
使用System.Linq;
使用SSRS=ReportConnector.SSRS;
使用SSRSExec=ReportConnector.SSRSExec;
Net系统;
命名空间报告SOAPConnection
{
公共静态类ReportRunner
{
公共静态字节[]报告(字符串服务器名、字符串报告位置、网络凭据aCred、字符串连接、字符串报告格式、字典报告参数)
{
SSRS.ReportingService2010 rptService=新的SSRS.ReportingService2010();
SSRSExec.ReportExecutionService rptExecute=新的SSRSExec.ReportExecutionService();
尝试
{
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;
尝试
{
SSRS.ItemParameter[]itemparams=rptService.GetItemParameters(reportLocation,null,true,null,null);
SSRSExec.ParameterValue[]execParameterValues=新的SSRSExec.ParameterValue[itemparams.Count()];
int参数索引=0;
if(itemparams!=null)
{
foreach(itemparams中的var rp)
{
SSRSExec.ParameterValue assignThis=新的SSRSExec.ParameterValue();
assignThis.Label=rp.Name;
assignThis.Name=rp.Name;
if(报告参数ContainsKey(rp.Name))
assignThis.Value=ReportParams[rp.Name];
其他的
{
assignThis.Value=null;
}
execParameterValues[paramIndex++]=assignThis;
}
SetExecutionParameters(ExecutParameterValues,“ru-ru”);
}
字符串模拟类型;
字符串扩展;
字符串[]流线;
字符串编码;
SSRSExec.警告[]警告;
reportBytes=rptExecute.Render(reportformat,//报告输出格式
无效的
延伸,
输出mimeType,
输出编码,
发出警告,,
外流线);
}
最后
{
}
返回reportBytes;
}
//抛出新异常(string.Format(“{0},服务器{1},RL={2}源={3}目标站点={4}ST={5}”,E.Message,serverName,reportLocation,E.Source,E.TargetSite,E.StackTrace),E);
最后
{
rptService.Dispose();
rptcexecute.Dispose();
}
}
}
}
班级计划
{
静态void Main(字符串[]参数)
{
线程th=null;
对于(int i=0;i<50;i++)
{
th=新螺纹(运行);
th.Start();
}
Console.WriteLine();
Console.WriteLine(“按以终止客户端”);
Console.ReadKey();
}
静态无效运行()
{
ReportRunner.Report(“http://srv-test“,”/Dx/Reports/Cln/Inventory“,
新网络凭证(“用户”、“pwd”、“VC”),空,“PDF”,
新词典{{“FId”,“1”},{“报告Id”,“24921”},{“日期”,“2016-10-04”});
}
}
rptExecute.Render-引发异常
System.Web.Services.dll中发生类型为“System.Net.WebException”的未处理异常
HTTP 503:服务器错误
如果我不使用多线程,一切正常。我做错了什么?
感谢您的帮助。更改rsreportserver.config中的以下键值以执行并发请求 默认值为20
<Add Key="MaxActiveReqForOneUser" Value="20"/>
谢谢。这有助于避免错误503。但我还有一个错误:所有请求和处理都需要连接到数据库。-->System.InvalidOperationException:超时已过期。从池中获取连接之前经过的超时时间。发生这种情况的原因可能是所有池连接都在使用中,并且已达到最大池大小。我试图在reports datasource中将最大池大小设置为5000,但SSR似乎忽略了这个参数。