JasperServer报告问题+ C#+ Soap协议

时间:2014-05-05 20:20:00

标签: c# soap jasper-reports jasperserver

首先,我既不使用C#也不使用Web服务。 我正在尝试在我的C#应用​​程序中运行Jasper Server上生成的报告,并在运行以下代码时返回错误500(内部服务器错误):

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\">HTML</argument>");
sb.AppendFormat("    <resourceDescriptor name=\"\" wsType=\"\" uriString=\"/reports/samples/Accounts Report\" isNew=\"false\">");
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();

我已经在互联网上看了很长时间了,没有什么能帮助我...

Ps。:我运行了jasper服务器并且凭据是正确的。我也需要使用Soap,而不是Rest,并且必须使用C#。我已经使用PHP,但它不是目标。

1 个答案:

答案 0 :(得分:0)

我终于发现了什么是错的。 XML中缺少标记。

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("<![CDATA[<request operationName=\"runReport\" locale=\"br\">");
sb.AppendLine("<argument name=\"RUN_OUTPUT_FORMAT\">HTML</argument>");
sb.AppendFormat("<resourceDescriptor name=\"Accounts Report\" wsType=\"reportUnit\" uriString=\"/reports/samples/AllAccounts\" isNew=\"false\">");
sb.AppendLine("</resourceDescriptor>");
sb.AppendLine("</request>]]>");
sb.AppendLine("</requestXmlString>");
sb.AppendLine("</q1:runReport>");
sb.AppendLine("</s:Body></s:Envelope>");