1
A
回答
2
其他答案当然是有效的,但是Play为这类东西提供了一些方便的类。但您需要手动解析响应。 从WS
开始。它可以用于发布/获取任何各种服务。我将它用于SOAP请求和REST调用。
例子:
HttpResponse httpResponse = null;
String username = "";
String password = "";
String url = "";
String postBody = "";
try {
httpResponse = WS.url(url)
.authenticate(username, password)
.setHeader("Content-Type", "text/xml; charset=UTF-8")
.setHeader("SOAPAction", "")
.body(postBody).post();
Document document = httpResponse.getXml();
String value = XPath.selectText("//value", document);
Node node = XPath.selectNode("//node", document);
// Do things with the nodes, value and so on
} catch (Exception e) {
Logger.error("Do something with the connection error: %s", e);
}
正如你所看到的,我用的是XPath
类解析返回Document
。它提供了遍历文档的各种有用方法。
1
使用播放为SOAP消费者应该很简单:包括您选择的soap库,从wsdl生成存根,调用端点。另一种选择是调用URL并使用Xpath来解析其信封。
谢谢,有没有什么限制?如果有任何记录的标准(基于玩团队)的方式来做到这一点?或者我只是按照我以前在比赛之外做的方式。 – ehsun7b 2013-03-27 07:46:25
使用您选择的SOAP客户端工具包。阅读谷歌群组发布的问题以了解更多信息:https://groups.google.com/group/play-framework/search?group=play-framework&q=soap – 2013-03-27 07:52:58