Reputation: 19
Good day to all. I try to use ssrs web service with such code.
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 - throws an exception An unhandled exception of type 'System.Net.WebException' occurred in System.Web.Services.dll HTTP 503: Server Error.
If I don't use multithreading all ok. What I've done wrong? Thanks for you help.
Upvotes: 1
Views: 1174
Reputation: 125
Change following key Value in rsreportserver.config to do concurrent Request.
Default Value is 20
<Add Key="MaxActiveReqForOneUser" Value="20"/>
Upvotes: 2