You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-dev@axis.apache.org by Simon Fell <sf...@salesforce.com> on 2005/10/04 05:03:07 UTC
[axis2] client code
I couldn't spot an obvious tutorial or sample for a doc/literal client generated from WSDL, so this is what i ended up with, but it seems very verbose, is there some trick I'm missing ? (there's 23 lines of code to make 2 WS call, the second call requiring a single header, the equivilent Axis 1.1 code is 7 lines, so that's a 3x "improvement" <g>)
Whats with the double nested objects for headers and request bodies ?
public static void main(String[] args) throws Exception {
SoapStub stub = new SoapStub();
CallOptionsDocument od = CallOptionsDocument.Factory.newInstance();
CallOptions options = CallOptions.Factory.newInstance();
od.setCallOptions(options);
Login l = Login.Factory.newInstance();
l.setUsername("[username]");
l.setPassword("[password]");
LoginDocument ld = LoginDocument.Factory.newInstance();
ld.setLogin(l);
LoginResult lr = stub.login(ld, od).getLoginResponse().getResult();
System.out.println("new SessionId is " + lr.getSessionId());
System.out.println("new ServerUrl is " + lr.getServerUrl());
stub = new SoapStub(null, lr.getServerUrl());
SessionHeaderDocument sd = SessionHeaderDocument.Factory.newInstance();
SessionHeader session = SessionHeader.Factory.newInstance();
session.setSessionId(lr.getSessionId());
sd.setSessionHeader(session);
QueryOptionsDocument qod = QueryOptionsDocument.Factory.newInstance();
QueryOptions qo = QueryOptions.Factory.newInstance();
qod.setQueryOptions(qo);
QueryDocument queryD = QueryDocument.Factory.newInstance();
Query query = Query.Factory.newInstance();
query.setQueryString("select id, name, accountNumber from Account");
queryD.setQuery(query);
QueryResult qres = stub.query(queryD, sd, od, qod).getQueryResponse().getResult();
System.out.println("total query size is " + qres.getSize());
}