IronPython call to SSRS - how to handle mutable arrays
I'm attempting to translate the following C# code into IronPython but I don't know how to handle the strongly typed mutable arrays. The code is test code to write a Server Side SSRS report to a local PDF, and runs fine in C#.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Data;
using System.Drawing.Imaging;
using System.Drawing.Printing;
using System.Collections.Generic;
using Microsoft.Reporting.WinForms;
namespace ConsoleBooking
{
class Program
{
static void Main(string[] args)
开发者_运维技巧{
ServerReport report = new ServerReport();
report.ReportServerUrl = new Uri("http://192.168.1.29/ReportServer");
report.ReportPath = "/Report Project Media Bookings/Business";
Warning[] warnings;
string[] streamids;
string mimeType;
string encoding;
string filenameExtension;
byte[] bytes = report.Render(
"PDF", null, out mimeType, out encoding, out filenameExtension,
out streamids, out warnings);
string filename = Path.Combine(Path.GetTempPath(), "business.pdf");
using (FileStream fs = new FileStream(filename, FileMode.Create))
{
fs.Write(bytes, 0, bytes.Length);
}
}
}
}
If I set the arrays up as
streamids = Array.CreateInstance(String, 1)
so my call looks like this
bytes = report.Render("PDF", None, mimeType, encoding, filenameExtension, streamids, warnings)
Then I get this rather enigmatic unhandled exception returned
expected StrongBox[str], got str
How should I code this?
The above report doesn't take any parameters, but in C# these are added using
List<ReportParameter> paramList = new List<ReportParameter>();
paramList.Add(new ReportParameter("pBookingID", "6761", false));
report.SetParameters(paramList);
Which again works fine for me in a related report - how do I add this in IronPython?
UPDATE: using bytes, mimeType, encoding, filenameExtension, streamids, warnings = report.Render("PDF", null) as suggested by Jeff Hardy gets over the immediate call, but it still crashes with a 'too many values to unpack' error. Arbitrarily extending the size of the arrays or adding extra parameters does not change this error - and it's difficult to see what's going wrong. Any ideas?
For the first problem, see the documentation on ref and out parameters. Basically, out parameters become part of a returned tuple. This would look something like (untested):
bytes, mimeType, encoding, filenameExtension, streamids, warnings = report.Render("PDF", null)
For the second, try:
from System.Collections.Generic import List
params = [ReportParameter("pBookingID", "6761", False), ...]
report.SetParam(List[ReportParameter](params))
精彩评论