- 论坛徽章:
- 0
|
关掉isa防火墙
xfire方式
public class XfireClient {
public static void main(String[] args) throws MalformedURLException,Exception {
//XFire client
Client client = new Client(new URL(
"
http://www.abc.com/server.php?wsdl
"));
//第一个参数是方法名,后面的参数是需要传入的参数
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 = "
http://www.abc.com/server.php
";
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(
"
http://www.abc.com/server.php
");
// 将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生成客户端
http://www.abc.com/server.php?wsdl
需要后面加wsdl,验证警告不必管它,可以成功生成客户端。
本文来自ChinaUnix博客,如果查看原文请点:http://blog.chinaunix.net/u3/110188/showart_2152347.html |
|