在Play 1.x框架中使用SOAP Web服务 [英] Consume SOAP Web-service in Play 1.x framework

查看:87
本文介绍了在Play 1.x框架中使用SOAP Web服务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只想知道有什么方法可以在Play框架(特别是1.x.x版)中使用SOAP Web服务.

I just want to know is there any way to consume a SOAP web-service inside Play framework specifically version 1.x.x

谢谢

推荐答案

其他答案当然是有效的,但是Play附带了一些方便的此类类.但是,您将需要手动解析响应. 从WS类开始.它可以用于发布/获取或与各种服务一起使用.我将它用于SOAP请求和REST调用.

The other answers are of course valid, but Play comes with a few handy classes for this kind of stuff. You will need to parse the response by hand though. Start with the WS class. It can be used to post/get or whatever with all kinds of services. I use it for SOAP requests and REST calls for instance.

示例:

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.它提供了各种遍历文档的有用方法.

As you can see, I use the XPath class to parse the returned Document. It offers all kinds of useful methods to traverse the Document.

这篇关于在Play 1.x框架中使用SOAP Web服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆