18

Jasper Reports は、Crystal Reports に代わる優れたオープン ソースです。レターや請求書などの単一ページの PDF ページから複数ページのレポートに最適です。ただし、.NET との親和性はあまり高くなく、C#/Mono を JasperServer とうまく連携させることは実りがありませんでした。

JasperServer で C# からレポートを実行し、XML データセットを SOAP リクエストに添付する方法のコード サンプルを入手した人はいますか? Mono で動作する必要があるため、Microsoft.Web.Services2 は問題外です。

私は自分のソープリクエストを転がそうとしました。Jasper Server はそれを受け入れているようですが、サーバー 500 エラー以外の応答が得られないようです。MTOMアタッチメントを付けるまでには至りませんでした。

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();
4

2 に答える 2

2

Jasper は、あなたが既に見つけたWeb サービス APIを提供します。XML を使用した Web サービスであるため、サービス記述 (WSDL) をその言語のサービス スタブに変換すると、この場合は C# などの任意の言語からアクセスできます。

その特定のリンクには、Jasper Reports wsdl ファイルの場所があり、それらにアクセスした後、特定の XML インターフェイスへのコード レベル アクセスであるスタブを作成する必要があります。Mono の場合、これはこのチュートリアルに従って簡単なコマンド ライン コマンドで実行できます。残りの作業は、このコードを好きなように使用することです。

正確なコマンドはこれらの 2 つのリンクから見つけることができますがwsdl.exe、特定のパス (例: http://localhost:8080/jasperserver/services/repository?wsdl ) を引数として 1 つのコマンドを実行するだけです。次に、 SomeService.csを前のコマンドの出力であったファイルの名前にmcs /target:library SomeService.cs -r:System.Web.Services置き換えるのと同様のコマンドで結果をコンパイルします。

それでおしまい!

于 2011-12-06T15:12:03.633 に答える
0

I ran into the same problem not in mono but using Visual Studio. I always get error 500. That's because the answer of jasperserver according to the microsoft/mono code is not SOAP complient. ASP.NET expects a text/xml structure, and jasperserver sends a multipart structure back with the xml as the first part and the report as an attachment in the second part.

ASP.NET gives an exception on that. I am now trying to do a similar thing using REST, but I've not succeeded so far.

Addition: 2012-03-09 Figured out using REST, see Get report from jasperserver using REST webservice and asp.net C#

By the way, that is also working in Mono! (I develop in Visual Studio, but deploy on Mono)

于 2012-03-08T19:45:45.587 に答える