Java: simple soap client
I am looking for a soap client for Java
Apache axis looks blo swollen to me I don't understand why Java has to be so complex 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); ?>
My $response object contains all the information I need
Can someone advise me how to implement such a thing in Java without too much trouble?
Thank you in advance,
~ edit 1 ~
@jarnbjo:
This is very useful to me What I insist on is, what import do I need to make the code run?
I ran this command: SH wsdl2java SH - O output - A - URI https://api.betfair.com/global/v3/BFGlobalService.wsdl
And establish the output Do you think this is faster than PHP? In addition, I have an "asynchronous" option Does this mean I can make asynchronous calls? This will be very useful I want to run all this in a Java - based web socket server
Solution
Unless you need the additional functions provided by the soap API client in the standard Java API, you can use the wsimport tool (pointing to your WSDL URL) in the bin directory of the JDK and generate a Java class for its service appearance
Using the generated class, you need more java code to execute the request than in your PHP example, 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 it may be because the session token is invalid