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

查看:46
本文介绍了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

I ran this command: sh wsdl2java.sh -o output -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天全站免登陆