Chinaunix首页 | 论坛 | 博客
  • 博客访问: 460576
  • 博文数量: 155
  • 博客积分: 2954
  • 博客等级: 少校
  • 技术积分: 1000
  • 用 户 组: 普通用户
  • 注册时间: 2010-01-12 22:00
文章分类

全部博文(155)

文章存档

2014年(2)

2013年(5)

2012年(10)

2011年(33)

2010年(105)

我的朋友

分类: Java

2010-01-18 18:09:58

关掉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,验证警告不必管它,可以成功生成客户端。
阅读(2164) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~