关掉isa防火墙
xfire方式
public class XfireClient {
public static void main(String[] args) throws MalformedURLException,Exception {
//XFire client
Client client = new Client(new URL(
""));
//第一个参数是方法名,后面的参数是需要传入的参数
Object[] results = client.invoke("publish", new Object[]{"localhost","abc"});
System.out.println((String)results[0]);
}
}
axis1.4方式
public class AxisClient {
private final static String endpoint = "";
public static void main(String[] args) throws Exception {
Service service = new Service();
Call call = (Call) service.createCall();
call.setTargetEndpointAddress(new URL(endpoint));
call.setOperationName(new QName("urn","publish"));
call.addParameter("hostname", XMLType.XSD_STRING, ParameterMode.IN);
call.addParameter("username", XMLType.XSD_STRING, ParameterMode.IN);
call.setReturnType(XMLType.XSD_STRING);
String result = (String) call.invoke(new Object[] { "localhost","root });
System.out.println(result);
}
}
axis2方式
public class AxisClient {
public static void main(String[] args) throws Exception {
RPCServiceClient serviceClient = new RPCServiceClient();
Options options = serviceClient.getOptions();
// 这一步指定了该服务的提供地址
EndpointReference targetEPR = new EndpointReference(
"");
// 将option绑定到该服务地址
options.setTo(targetEPR);
// 添加具体要调用的方法,这个可以从该服务的wsdl文件中得知
// 第一个参数是该服务的targetNamespace,第二个为你所要调用
// 的operation名称
QName opAdd =
new QName("urn", "publish");
//设置返回值类型
Class[] returnTypes = new Class[] {String.class};
//设置调用的参数
Object[] opAddArgs = new Object[] {"localhost","root"};
//调用服务,获得返回值
Object[] response = serviceClient.invokeBlocking(opAdd, opAddArgs, returnTypes);
String res = (String)response[0];
if (res == null) {
System.out.println("wrong");
return;
}
System.out.println(res);
}
myeclipse5.5.1生成客户端
需要后面加wsdl,验证警告不必管它,可以成功生成客户端。
阅读(2202) | 评论(0) | 转发(0) |