[Apache提供]直接通过AXIS调用远程的web service
我认为这种调用方式适合比较那种返回比较简单的数据的service, 比如,天气预报,这些内容肯定可以通过一个很简单的xml来返回。还有就是WebSSO,返回的就是一个字符串。
这种调用方式的好处就是简单(开发简单,调用简单,只要service提供方不改动对外的方法接口,客户端都无需有代码带动),无需对web service有太深了解,只要按照套路去掉用就可以了。
直接调用模式如下:
<<LogonClientWithURL.java>>
package ws.client;
import org.apache.axis.client.Call;
import org.apache.axis.client.Service;
public class LogonClientWithURL {
public static void main(String args[]) throws Exception {
try {
String urlname = "http://192.168.194.23:9080/Logon/services/Logon?wsdl" ;
urlname = "http://192.168.194.23:9080/Logon/services/Logon";
Service s = new Service();
Call call = (Call) s.createCall();
call.setTimeout(new Integer(5000));
call.setOperation( "getSecurityToken" );
call.setTargetEndpointAddress(urlname);
Object[] fn01 = { "john" , "john" , null ,null };
String val = (String)call.invoke(fn01);
System.out .println( "getSecurityToken(correct):" + val);
Object[] fn02 = { "john" , "john2" , null ,null };
String va2 = (String)call.invoke(fn02);
System.out .println( "getSecurityToken(wrong):" + va2);
} catch (Exception e) {
//java.io.InterruptedIOException: Read timed out
System.out.println(e.getMessage());
}
}
}
感谢原博主
原地址:http://blog.youkuaiyun.com/lxqluo/article/details/6968599