【发布时间】:2015-05-17 05:55:12
【问题描述】:
您好,我进行了一些研究,但仍然无法解决我的问题。我必须从我的bank 获取一个值并打印该值。他们提供了一个带有以下代码的 Web 服务站点(已经用正确的值替换了变量)
以下是示例 SOAP 1.2 请求和响应。显示的占位符需要替换为实际值。
POST /indicadoreseconomicos/WebServices/wsIndicadoresEconomicos.asmx HTTP/1.1
Host: indicadoreseconomicos.bccr.fi.cr
Content-Type: application/soap+xml; charset=utf-8
Content-Length: length
<?xml version="1.0" encoding="utf-8"?>
<soap12:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://www.w3.org/2003/05/soap-envelope">
<soap12:Body>
<ObtenerIndicadoresEconomicosXML xmlns="http://ws.sdde.bccr.fi.cr">
<tcIndicador>317</tcIndicador>
<tcFechaInicio>14/05/2015</tcFechaInicio>
<tcFechaFinal>15/05/2015</tcFechaFinal>
<tcNombre>Bove</tcNombre>
<tnSubNiveles>S</tnSubNiveles>
</ObtenerIndicadoresEconomicosXML>
</soap12:Body>
</soap12:Envelope>
这是我到目前为止所做的
public class ParseTest {
public static void parse() throws IOException, TransformerConfigurationException, TransformerException {
String fileRequestInput = "src/parsetest/XMLBanco.xml";
File xmlFileRequest = new File(fileRequestInput);
File file = new File(fileRequestInput);
FileInputStream fstreamRequest = new FileInputStream(xmlFileRequest);
DocumentBuilderFactory docFactory = null;
DocumentBuilder docBuilder = null;
Document document = null;
try {
docFactory = DocumentBuilderFactory.newInstance();
docBuilder = docFactory.newDocumentBuilder();
document = docBuilder.parse(fstreamRequest);
} catch (Exception e) {
System.out.println("FAILED");
}
System.out.println("Request xml generated Parsed succesffully ");
System.out.println(document);
Transformer transformer = TransformerFactory.newInstance().newTransformer();
transformer.setOutputProperty(OutputKeys.INDENT, "yes");
//initialize StreamResult with File object to save to file
StreamResult result = new StreamResult(new StringWriter());
DOMSource source = new DOMSource(document);
transformer.transform(source, result);
String xmlString = result.getWriter().toString();
System.out.println(xmlString);
}
}
XML 文件:
<?xml version="1.0" encoding="UTF-8"?>
<soap12:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://www.w3.org/2003/05/soap-envelope">
<soap12:Body>
<ObtenerIndicadoresEconomicosXML xmlns="http://ws.sdde.bccr.fi.cr">
<tcIndicador>317</tcIndicador>
<tcFechaInicio>14/05/2015</tcFechaInicio>
<tcFechaFinal>15/05/2015</tcFechaFinal>
<tcNombre>Bove</tcNombre>
<tnSubNiveles>S</tnSubNiveles>
</ObtenerIndicadoresEconomicosXML>
</soap12:Body>
</soap12:Envelope>
如何解析响应并打印响应值? 感谢您的帮助!
【问题讨论】:
-
看看他们是否有WSDL文件,然后你可以从中生成java客户端代码,然后你可以使用它的方法来获取你想要的值。
标签: java html xml web-services soap