posts - 75,comments - 83,trackbacks - 0
1.先下载axis-bin-1_4拿到所需要的jar包
我用的jar如下:

1.在eclipse中创建web项目
2.再把jar包COPY到lib目录下
3.在web.xml中加入以下代码:

<listener>
        <listener-class>org.apache.axis.transport.http.AxisHTTPSessionListener</listener-class>
    </listener>
   
  <servlet>
    <servlet-name>AxisServlet</servlet-name>
    <display-name>Apache-Axis Servlet</display-name>
    <servlet-class>
        org.apache.axis.transport.http.AxisServlet
    </servlet-class>
  </servlet>
 
  <servlet>
    <servlet-name>AdminServlet</servlet-name>
    <display-name>Axis Admin Servlet</display-name>
    <servlet-class>
        org.apache.axis.transport.http.AdminServlet
    </servlet-class>
    <load-on-startup>100</load-on-startup>
  </servlet>

  <servlet>
    <servlet-name>SOAPMonitorService</servlet-name>
    <display-name>SOAPMonitorService</display-name>
    <servlet-class>
        org.apache.axis.monitor.SOAPMonitorService
    </servlet-class>
    <init-param>
      <param-name>SOAPMonitorPort</param-name>
      <param-value>5001</param-value>
    </init-param>
    <load-on-startup>100</load-on-startup>
  </servlet>

 

  <servlet-mapping>
    <servlet-name>AxisServlet</servlet-name>
    <url-pattern>/services/*</url-pattern>
  </servlet-mapping>

  <servlet-mapping>
    <servlet-name>SOAPMonitorService</servlet-name>
    <url-pattern>/SOAPMonitor</url-pattern>
  </servlet-mapping>

4.创建服务端类

package server;
public class SayHello {
 public String getName(String name)
    {
        return "hello "+name;
    }
}

5.编写WebRoot\WEB-INF\deploy.wsdd文件

<deployment xmlns="http://xml.apache.org/axis/wsdd/" xmlns:java="http://xml.apache.org/axis/wsdd/providers/java">
<service name="SayHello" provider="java:RPC">
<parameter name="className" value="server.SayHello"/>
<parameter name="allowedMethods" value="*"/>
<parameter name="scope" value="request"/>
</service>
</deployment>

6.在tomcat中启动项目

7.

  打开cmd 进入 目录 :WEB-INF\

  输入部署命令(注意更改命令中服务的地址和端口)

  java -Djava.ext.dirs=lib org.apache.axis.client.AdminClient -lhttp://localhost:8080/axis/services   deploy.wsdd

  若显示
  Processing file deploy.wsdd
  <Admin>Done processing</Admin>

  则表示发布服务成功

8.在浏览器中输入地址
   http://localhost:8080/axitDemo/services
   会显示你所发布的服务

And now... Some Services

点击  SayHello (wsdl)   便会显示其XML ,点右健,查看源文件,保存XML为WebRoot\WEB-INF\SayHello.xml


 9.创建客户端
  编写axitDemo\WebRoot\WEB-INF\make.bat文件  内容如下

  java -cp ".;lib\axis-ant.jar;lib\axis.jar;lib\commons-discovery-0.2.jar;lib\commons-logging-1.0.4.jar;lib\jaxrpc.jar;lib\log4j-1.2.8.jar;lib\log4j.properties;lib\saaj.jar;lib\wsdl4j-1.5.1.jar" org.apache.axis.wsdl.WSDL2Java -p %1 %2


10. 打开cmd进入WEB-INF目录
    执行命令: make  com.webserivce  SayHello.xml
   成功后会在WEB-INF目录下生成
com.webserivce  包下面会有java类 如下图:


COPY    com.webserivce包到SRC目录下

12.编写客户端测试Client 类


package client;

import java.rmi.RemoteException;

import com.webserivce.SayHelloServiceLocator;
import com.webserivce.SayHello_PortType;


public class Client {
 private SayHello_PortType dataService;
 public Client()throws Exception{
  SayHelloServiceLocator service= new SayHelloServiceLocator();
 
      this.setDataService(service.getSayHello());
 }

 private String getName(String name) throws RemoteException{
  return dataService.getName(name);
  
 }
 public static void main(String[] args)throws Exception {
  Client c = new Client();
  String a = c.getName("Test axis!");
  System.out.println(a);
 }

 public SayHello_PortType getDataService() {
  return dataService;
 }

 public void setDataService(SayHello_PortType dataService) {
  this.dataService = dataService;
 }
 
}


运行Client 类

hello  Test axis! 

整个过程就完成啦。。。。。

posted on 2011-05-25 11:53 梓枫 阅读(930) 评论(0)  编辑  收藏 所属分类: webservice

只有注册用户登录后才能发表评论。


网站导航:
博客园   IT新闻   Chat2DB   C++博客   博问