Java:简单的SOAP客户端 [英] Java: Simple SOAP Client

查看:533
本文介绍了Java:简单的SOAP客户端的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找Java的SOAP客户端。

I'm looking for a SOAP client for Java.

Apache Axis看起来非常臃肿。我不明白为什么Java必须如此复杂。例如,在PHP中,我所要做的就是:

Apache Axis looks very bloated to me. I don't understand why things have to be so complicated in Java. For example, in PHP, all I have to do is:

<?php
$global_service_wsdl='https://api.betfair.com/global/v3/BFGlobalService.wsdl';
$betfair=new SoapClient($global_service_wsdl);

$params=array("request"=>
    array("header"=>
         array("clientStamp"=>0,"sessionToken"=>$session_token)),"locale"=>""
);
$response=$betfair->getAllEventTypes($params);
?>

我的$ response对象包含我需要的所有信息。

And my $response object holds all the information I require.

有人可以建议我如何在Java中实现这样的东西而不会有太多麻烦吗?

Can anybody suggest how I would implement something like this in Java without too much hassle?

非常感谢提前,

〜编辑1~

@jarnbjo:

这对于我。我坚持的是我需要输入什么才能运行该代码?

That is very useful to me. The bit I'm stuck on is what imports do I need to get that code to run?

我运行了这个命令:
sh wsdl2java.sh -o输出-a -uri https://api.betfair.com/global/v3/BFGlobalService。 wsdl

并构建输出。你觉得这比PHP快吗?另外,我有一个异步选项。这是否意味着我可以进行异步调用?这将非常有用。我想在基于Java的websocket服务器中运行所有这些。

And built the output. Do you think this is quicker than PHP? Also, I've got an "asynchronous" option. Does this mean I can make asynchronous calls? That would be very useful. I'd like to run all this inside a Java-based websocket server.

推荐答案

除非您需要其他功能,否则在标准Java API中的SOAP客户端,您可以使用JDK的bin目录中的wsimport工具(将其指向您的WSDL URL)并让它为服务外观生成Java类。

Unless you require additional functionality not provided by the SOAP client in the standard Java API, you can use the wsimport tool in the JDK's bin directory (point it to your WSDL URL) and let it generate Java classes for the service facade.

使用生成的类,您需要比PHP示例中更多的Java代码来执行请求,但它仍然是合理的:

With the generated classes, you need some more Java code than in your PHP example to perform the request, but it's still reasonable:

BFGlobalService betfair = new BFGlobalService_Service().getBFGlobalService();

APIRequestHeader header = new APIRequestHeader();
header.setClientStamp(0);
header.setSessionToken("someSessionToken");

GetEventTypesReq req = new GetEventTypesReq();
req.setHeader(header);
req.setLocale("");

GetEventTypesResp response = betfair.getAllEventTypes(req);

此示例失败并显示错误,但可能是因为会话令牌无效。

This example fails with an error, but probably because the session token is invalid.

这篇关于Java:简单的SOAP客户端的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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