- 論壇徽章:
- 0
|
關(guān)掉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
"));
//第一個(gè)參數(shù)是方法名,后面的參數(shù)是需要傳入的參數(shù)
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();
// 這一步指定了該服務(wù)的提供地址
EndpointReference targetEPR = new EndpointReference(
"
http://www.abc.com/server.php
");
// 將option綁定到該服務(wù)地址
options.setTo(targetEPR);
// 添加具體要調(diào)用的方法,這個(gè)可以從該服務(wù)的wsdl文件中得知
// 第一個(gè)參數(shù)是該服務(wù)的targetNamespace,第二個(gè)為你所要調(diào)用
// 的operation名稱
QName opAdd =
new QName("urn", "publish");
//設(shè)置返回值類型
Class[] returnTypes = new Class[] {String.class};
//設(shè)置調(diào)用的參數(shù)
Object[] opAddArgs = new Object[] {"localhost","root"};
//調(diào)用服務(wù),獲得返回值
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,驗(yàn)證警告不必管它,可以成功生成客戶端。
本文來自ChinaUnix博客,如果查看原文請點(diǎn):http://blog.chinaunix.net/u3/110188/showart_2152347.html |
|