IronPython 调用 SSRS - 如何处理可变数组
我正在尝试将以下 C# 代码转换为 IronPython,但我不知道如何处理强类型可变数组。该代码是将服务器端 SSRS 报告写入本地 PDF 的测试代码,在 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);
}
}
}
}
如果我将数组设置为这样,
streamids = Array.CreateInstance(String, 1)
我的调用看起来像这样
bytes = report.Render("PDF", None, mimeType, encoding, filenameExtension, streamids, warnings)
然后我得到这个相当神秘的未处理异常返回
期望 StrongBox[str],得到 str
我应该如何编码?
上面的报告不带任何参数,但在 C# 中,这些参数是通过
List<ReportParameter> paramList = new List<ReportParameter>();
paramList.Add(new ReportParameter("pBookingID", "6761", false));
report.SetParameters(paramList);
在相关报告中使用 Which 再次工作得很好来添加的 - 如何在 IronPython 中添加它?
更新:按照 Jeff Hardy 的建议使用 bytes、mimeType、encoding、filenameExtension、streamids、warnings = report.Render("PDF", null) 可以克服立即调用,但它仍然崩溃并出现“太多值无法解包”错误。任意扩展数组的大小或添加额外的参数不会改变此错误 - 并且很难看出出了什么问题。有什么想法吗?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
对于第一个问题,请参阅 ref 上的文档和out参数。基本上,输出参数成为返回元组的一部分。这看起来像(未经测试):
对于第二个,尝试:
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):
For the second, try: