从 C# 在 JasperServer 上运行报告

Running report on JasperServer from C#(从 C# 在 JasperServer 上运行报告)
本文介绍了从 C# 在 JasperServer 上运行报告的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Jasper Reports 是 Crystal Reports 的出色开源替代品.它非常适合单页 PDF 页面,例如字母和发票到多页报告.然而,它对 .NET 不是很友好,并且让 C#/Mono 与 JasperServer 配合得很好也没有什么成果.

Jasper Reports is a superb open source alternative to Crystal Reports. It's great for single page PDF pages such as letters & invoices to multi-page reports. However it's not very .NET friendly, and getting C#/Mono to play nice with JasperServer has not been fruitful.

有没有人知道如何从 C# 在 JasperServer 上运行报告,并在 SOAP 请求中附加 XML 数据集的代码示例?它需要在 Mono 上工作,所以 Microsoft.Web.Services2 是不可能的.

Has anyone got any code samples of how to run a report on JasperServer from C#, and attach an XML dataset with the SOAP request? It needs to work on Mono, so Microsoft.Web.Services2 is out of the question.

我尝试提出自己的肥皂请求.Jasper Server 似乎接受了它,但除了服务器 500 错误之外,我似乎无法得到任何响应.我还没有附加 MTOM 附件.

I had a go at trying to roll my own soap request. Jasper Server seems to accept it, but I cant seem to get any response back other than a server 500 error. I didn't get as far as attaching a MTOM attachment.

var sb = new StringBuilder();

sb.AppendLine("<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">");
sb.AppendLine("<s:Body s:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">");
sb.AppendLine("<q1:runReport xmlns:q1="http://axis2.ws.jasperserver.jaspersoft.com">");

sb.AppendLine("<requestXmlString xsi:type="xsd:string">");
sb.AppendLine("<request operationName="runReport" locale="en">");
sb.AppendLine("    <argument name="RUN_OUTPUT_FORMAT">PDF</argument>");
sb.AppendFormat("    <resourceDescriptor name="" wsType="" uriString="{0}" isNew="false">", "/JourneyReport");
sb.AppendLine("      <label>null</label>");
sb.AppendLine("      <parameter name="testparam">1</parameter>");
sb.AppendLine("    </resourceDescriptor>");
sb.AppendLine("  </request>");
sb.AppendLine("</requestXmlString>");
sb.AppendLine("</q1:runReport>");
sb.AppendLine("</s:Body></s:Envelope>");


var webRequest = (HttpWebRequest)WebRequest.Create("http://localhost:8080/jasperserver/services/repository");
webRequest.Credentials = new NetworkCredential("jasperadmin","jasperadmin");
webRequest.PreAuthenticate = true;

webRequest.Headers.Add("SOAPAction","");

//Set HttpWebRequest properties
byte[]  bytes = System.Text.Encoding.UTF8.GetBytes(sb.ToString());
webRequest.Method = "POST";
webRequest.ContentLength = bytes.Length;
webRequest.ContentType = "text/xml; encoding='utf-8'";

//Get Stream object 
var objRequestStream = webRequest.GetRequestStream();
objRequestStream.Write(bytes, 0, bytes.Length);
objRequestStream.Close();

var response = (HttpWebResponse)webRequest.GetResponse();

推荐答案

Jasper 给出了一个 Web Services API 你已经找到了,我想.因为它是使用 XML 的 Web 服务,所以当您将服务描述 (WSDL) 转换为该语言上的服务存根时,可以通过任何语言(如本例中的 C#)访问它.

Jasper gives a Web Services API which you already have found, I suppose. For that being a Web Services using XML, it can be accessed through any language, like C# in this case, when you convert the service description (WSDL) to a service stub on that language.

在该给定链接上可以找到 Jasper Reports wsdl 文件位置,在访问它们之后,您的任务是创建存根,这是对给定 XML 接口的代码级访问.对于 Mono,这可以根据 本教程 和其余的工作就是以你想怎么用的方式使用这段代码.

On that given link there can be found Jasper Reports wsdl file locations and after having access to them your task is to create the stub, which is a code level access to the given XML interface. For Mono this can be done with a simple command line command according to this tutorial and the rest of the work is to use this code how ever you want to use it.

通过这两个链接可以找到确切的命令,没有什么魔力,但它就像一个命令以给定路径运行 wsdl.exe 一样简单(例如.http://localhost:8080/jasperserver/services/repository?wsdl) 作为参数,然后编译结果类似于 mcs/target:library SomeService.cs -r:System.Web.Services 的命令,您将 SomeService.cs 替换为作为输出的文件的名称上一条命令.

The exact command can be found through these two links with not much magic, but it is something as easy as one command running wsdl.exe with the given path (eg. http://localhost:8080/jasperserver/services/repository?wsdl) as argument and then compiling the result with a command similar to mcs /target:library SomeService.cs -r:System.Web.Services where you replace SomeService.cs with the name of the file that was the output of the previous command.

就是这样!

这篇关于从 C# 在 JasperServer 上运行报告的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

DispatcherQueue null when trying to update Ui property in ViewModel(尝试更新ViewModel中的Ui属性时DispatcherQueue为空)
Drawing over all windows on multiple monitors(在多个监视器上绘制所有窗口)
Programmatically show the desktop(以编程方式显示桌面)
c# Generic Setlt;Tgt; implementation to access objects by type(按类型访问对象的C#泛型集实现)
InvalidOperationException When using Context Injection in ASP.Net Core(在ASP.NET核心中使用上下文注入时发生InvalidOperationException)
LINQ many-to-many relationship, how to write a correct WHERE clause?(LINQ多对多关系,如何写一个正确的WHERE子句?)