`
eggbucket
  • 浏览: 184543 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

为你的项目加入webservice(axis)

 
阅读更多

如何使用axis为你的项目加入webservice


前提:已有一个web项目,名为testAxis ,路径:E:/eclipseWork/testAxis

1、下载axis包

http://www.apache.org/dyn/closer.cgi/ws/axis/1_4

下载 axis-bin-1_4.zip

解压到 E:/axis-1_4

2、配置axis

将 E:/axis-1_4/lib 里面的文件拷到 E:/eclipseWork/testAxis/web/WEB-INF/lib 下

编辑 E:/eclipseWork/testAxis/web/WEB-INF/web.xml

<welcome-file-list>
    <welcome-file>index.jsp</welcome-file>
  </welcome-file-list>

前加入:

  1. < servlet >   
  2.   < servlet-name > AxisServlet </ servlet-name >   
  3.   < servlet-class > org.apache.axis.transport.http.AxisServlet </ servlet-class >   
  4.  </ servlet >   
  5.  < servlet-mapping >   
  6.   < servlet-name > AxisServlet </ servlet-name >   
  7.   < url-pattern > /servlet/AxisServlet </ url-pattern >   
  8.  </ servlet-mapping >   
  9.  < servlet-mapping >   
  10.   < servlet-name > AxisServlet </ servlet-name >   
  11.   < url-pattern > *.jws </ url-pattern >   
  12.  </ servlet-mapping >   
  13.  < servlet-mapping >   
  14.   < servlet-name > AxisServlet </ servlet-name >   
  15.   < url-pattern > /services/* </ url-pattern >   
  16.  </ servlet-mapping >   
  17.    
  18.  < mime-mapping >   
  19.   < extension > wsdl </ extension >   
  20.   < mime-type > text/xml </ mime-type >   
  21.  </ mime-mapping >   
  22.  < mime-mapping >   
  23.   < extension > xsd </ extension >   
  24.   < mime-type > text/xml </ mime-type >   
  25.  </ mime-mapping >   

 

在向你的项目中加入的WebRoot目录中加入*.jws文件,这时访问你的项目名+*.jws 如:http://localhost/webservice/WSTestImpl.jws?wsdl 成功会在页面中出现wsdl文件

 

还可以如下配置:

编辑tomcat/conf/server.xml

 <Host name="localhost" debug="0" appBase="webapps"
       unpackWARs="true" autoDeploy="true"
       xmlValidation="false" xmlNamespaceAware="false">

后加入:

<Context docBase="E:/eclipseWork/testAxis/web" path="/testAxis" reloadable="true" />

启动tomcat 访问: http://localhost:8080/testAxis/services

可以看到:

And now... Some Services

 3、编写webservice服务端

在web项目下新建一个类

  1. package  com.neo.test;  
  2.   
  3. public   class  HelloWorld {  
  4.  public  String sayHello() {  
  5.   return   "hello" ;  
  6.  }  
  7. }  

4、注册服务

在 E:/eclipseWork/testAxis/web/WEB-INF 下新建文本文件 deploy.wsdd

  1. < deployment   xmlns = "http://xml.apache.org/axis/wsdd/"   xmlns:java = "http://xml.apache.org/axis/wsdd/providers/java" >   
  2.  < service   name = "SayHello"   provider = "java:RPC" >   
  3.   < parameter   name = "className"   value = "com.neo.test.HelloWorld" />   
  4.   < parameter   name = "allowedMethods"   value = "*" />   
  5.  </ service >   
  6. </ deployment >   

启动刚刚配置好的项目,并确保访问http://localhost:8080/testAxis/services 页面显示正常

打开cmd

cd E:/eclipseWork/testAxis/web/WEB-INF


E:/eclipseWork/testAxis/web/WEB-INF>java -Djava.ext.dirs=E:/eclipseWork/testAxis/web/WEB-INF/lib org.apache.axis.client.AdminClient -lhttp://localhost:8080/testAxis/servlet/AxisServlet deploy.wsdd

 

成功的话会显示:

Processing file deploy.wsdd
<Admin>Done processing</Admin>

并在 E:/eclipseWork/testAxis/web/WEB-INF 下面产生 server-config.wsdd 文件

重启tomcat,并访问 http://localhost:8080/testAxis/services  会发现多出来一个service

And now... Some Services

就说明你的配置成功了

 

5、测试webservice

访问 http://localhost:8082/testAxis/services/SayHello?wsdl

  1. <? xml   version = "1.0"   encoding = "UTF-8" ?>   
  2. < wsdl:definitions   targetNamespace = "http://localhost:8082/testAxis/services/SayHello"   xmlns:apachesoap = "http://xml.apache.org/xml-soap"   xmlns:impl = "http://localhost:8082/testAxis/services/SayHello"   xmlns:intf = "http://localhost:8082/testAxis/services/SayHello"   xmlns:soapenc = "http://schemas.xmlsoap.org/soap/encoding/"   xmlns:wsdl = "http://schemas.xmlsoap.org/wsdl/"   xmlns:wsdlsoap = "http://schemas.xmlsoap.org/wsdl/soap/"   xmlns:xsd = "http://www.w3.org/2001/XMLSchema" >   
  3. <!--WSDL created by Apache Axis version: 1.4  
  4. Built on Apr 22, 2006 (06:55:48 PDT)-->   
  5.   
  6.    < wsdl:message   name = "sayHelloRequest" >   
  7.   
  8.    </ wsdl:message >   
  9.   
  10.    < wsdl:message   name = "sayHelloResponse" >   
  11.   
  12.       < wsdl:part   name = "sayHelloReturn"   type = "xsd:string" />   
  13.   
  14.    </ wsdl:message >   
  15.   
  16.    < wsdl:portType   name = "HelloWorld" >   
  17.   
  18.       < wsdl:operation   name = "sayHello" >   
  19.   
  20.          < wsdl:input   message = "impl:sayHelloRequest"   name = "sayHelloRequest" />   
  21.   
  22.          < wsdl:output   message = "impl:sayHelloResponse"   name = "sayHelloResponse" />   
  23.   
  24.       </ wsdl:operation >   
  25.   
  26.    </ wsdl:portType >   
  27.   
  28.    < wsdl:binding   name = "SayHelloSoapBinding"   type = "impl:HelloWorld" >   
  29.   
  30.       < wsdlsoap:binding   style = "rpc"   mce_style = "rpc"   transport = "http://schemas.xmlsoap.org/soap/http" />   
  31.   
  32.       < wsdl:operation   name = "sayHello" >   
  33.   
  34.          < wsdlsoap:operation   soapAction = "" />   
  35.   
  36.          < wsdl:input   name = "sayHelloRequest" >   
  37.   
  38.             < wsdlsoap:body   encodingStyle = "http://schemas.xmlsoap.org/soap/encoding/"   namespace = "http://test.neo.com"   use = "encoded" />   
  39.   
  40.          </ wsdl:input >   
  41.   
  42.          < wsdl:output   name = "sayHelloResponse" >   
  43.   
  44.             < wsdlsoap:body   encodingStyle = "http://schemas.xmlsoap.org/soap/encoding/"   namespace = "http://localhost:8082/testAxis/services/SayHello"   use = "encoded" />   
  45.   
  46.          </ wsdl:output >   
  47.   
  48.       </ wsdl:operation >   
  49.   
  50.    </ wsdl:binding >   
  51.   
  52.    < wsdl:service   name = "HelloWorldService" >   
  53.   
  54.       < wsdl:port   binding = "impl:SayHelloSoapBinding"   name = "SayHello" >   
  55.   
  56.          < wsdlsoap:address   location = "http://localhost:8082/testAxis/services/SayHello" />   
  57.   
  58.       </ wsdl:port >   
  59.   
  60.    </ wsdl:service >   
  61.   
  62. </ wsdl:definitions >   

打开cmd

 

cd E:/eclipseWork/testAxis

 

E:/eclipseWork/testAxis>java -Djava.ext.dirs=E:/eclipseWork/testAxis/web/WEB-INF
/lib org.apache.axis.wsdl.WSDL2Java -oE:/eclipseWork/testAxis/src -pcom.neo.clie
nt http://localhost:8082/testAxis/services/SayHello?wsdl

 

执行后在src下产生 E:/eclipseWork/testAxis/src/com/neo/client 文件夹里面有四个java文件:

HelloWorld.java

HelloWorldService.java

HelloWorldServiceLocator.java

SayHelloSoapBindingStub.java

 

这是根据服务器端提供的wsdl生成的客户端需要的基础文件

 

在com.neo.client下新建一个类

  1. package  com.neo.client;  
  2.   
  3. import  java.rmi.RemoteException;  
  4. import  javax.xml.rpc.ServiceException;  
  5.   
  6. public   class  HelloWorldClient {  
  7.     public   void  testSayHello()  throws  ServiceException, RemoteException{  
  8.         HelloWorldService service = new  HelloWorldServiceLocator();  
  9.         HelloWorld client  = service.getSayHello();  
  10.         System.out.println(client.sayHello());  
  11.     }  
  12.       
  13.     public   static   void  main(String[] args) {  
  14.         HelloWorldClient client = new  HelloWorldClient();  
  15.         try  {  
  16.             client.testSayHello();  
  17.         } catch  (RemoteException e) {  
  18.             e.printStackTrace();  
  19.         } catch  (ServiceException e) {  
  20.             e.printStackTrace();  
  21.         }  
  22.     }  
  23. }  

直接运行,如果打印出 hello 就说明客户端调用成功!

 

转载:http://blog.csdn.net/nsrainbow/article/details/4131196

分享到:
评论

相关推荐

    SpringBoot开发WebService之Axis示例

    借鉴网上的资源,弄了一个SpringBoot开发WebService之Axis示例。

    如何在eclipse的 Axis插件自动生成的webService相关文件中加入SOAP-HTTP信息

    NULL 博文链接:https://cydia.iteye.com/blog/701773

    axis2-1.6.2.zip

    3、设置环境变量,加入AXIS2_HOME=&lt;Axis2客户端安装目录&gt;,path中追加;%AXIS2_HOME%\bin 4、打开cmd,执行命令 wsdl2java -uri ...

    Axis搭建一个简单的web工程

    搭建一个web工程,里面加入webservice中的Axis,用java编程实现在服务端提供一个求两数之和的方法。然后在客户端传递两个数字的参数到服务端 计算出结果返回到客户端。

    axis-src-1_4

    webservice 开发备的开发包,下载解压后把axis-1_4\webapps\axis\WEB-INF\lib下的文件拷贝到%tomcat_home%\comm\lib目录下,axis-1_4\lib下的所有包加入到eclipse

    制作webservice的库文件和使用方法

    这个是使用java语言,来制作的webservice,有详细的使用方法和齐全的库文件,这个库文件用来替换tomcat7.0的库文件,因为里面加入了很多axis2的库文件,所以可以少走很多的弯路,直接替换就可以了

    基于axis2的java与php通信源码及说明文档

    由于上传不能超过20M,AxisTest里面的包需要朋友自己去下载,网上找axis2-1.5.1-bin.zip这个文件,下载然后解压,拷贝lib下面的所有包,加入到项目的lib目录下就OK,然后发布到tomcat上,然后进行java 客户端的测试...

    axis2调用的ECLIPSE插件

    用于生成调用AXIS2发布的WEBSERVICE服务,自动生成STUB类。非常实用,生成STUB类后,需要在工程中加入AIXS2的相关JAR包才能调用服务。

    EOS5.x 的 WebService 服务配置及使用说明

    3.2 加入 axis 的 jar包到 CLASSPATH...................................................................................4 3.2.1 WebLogic8.x环境..............................................................

    backport-util-concurrent-3.1.jar

    - 注册此 jar 包: 編輯 %ECLIPSE_HOME%\plugins\Axis2_Codegen_Wizard_1.3.0\plugin.xml , 在 &lt;runtime&gt; 內加入下面的字串 &lt;library name="lib/backport-util-concurrent-3.1.jar"&gt; *"/&gt; &lt;/library&gt;

Global site tag (gtag.js) - Google Analytics