`
hulu26
  • 浏览: 222485 次
  • 性别: Icon_minigender_2
  • 来自: 上海
社区版块
存档分类
最新评论

Web Service 之 axis2

阅读更多
1. 环境准备
   下载axis2-eclipse-codegen-wizard.zip、axis2-eclipse-service-archiver-wizard.zip,这两个是eclipse的开发axis2的插件。
   将以上两个插件解压放到eclipse\plugins目录下。
   打开eclipse>>File>>new>>other下是否有Axis2 Wizards。

2. axis2插件开发webservice客户端:
http://www.blogjava.net/parable-myth/archive/2010/08/03/327802.html (需要启动服务器)

创建axis2出现java.lang.reflect.invocationtargetexception异常解决:
http://hefeidaxia.iteye.com/blog/501098

3. 生成客户端代码
   创建项目,命名为DynamicAxisClient。
   右击DynamicAxisClient>>new>>other>>Web Services>>Web service Client>>next>>选择服务器中的wsdl文件>>OK。
   src目录下会自动生成com\dynamic\axis\server包,包中包含5个java文件.

4. 编写AxisDynamicClient.java文件调用web service服务.
   package com.dynamic.axis.test;

   import java.net.MalformedURLException;
   import java.rmi.RemoteException;
   import org.apache.axis.AxisFault;
   import com.dynamic.axis.server.HelloWorldService;
   import com.dynamic.axis.server.HelloWorldServiceLocator;
   import com.dynamic.axis.server.HelloWorldSoapBindingStub;

   public class AxisDynamicClient {
      public static void main(String[] args) {
         HelloWorldService service = new HelloWorldServiceLocator();
         String url = service.getHelloWorldAddress();
         try {
            java.net.URL endpointURL = new java.net.URL(url);
            HelloWorldSoapBindingStub stub = new HelloWorldSoapBindingStub(endpointURL,null);
            String str = stub.sayHello("");
            System.out.println(str);
         } catch (MalformedURLException e) {
            e.printStackTrace();
         } catch (AxisFault e) {
            e.printStackTrace();
         } catch (RemoteException e) {
            e.printStackTrace();
         }
      }
   }
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics