1.下载axis 1.4
2.创建MyEclipse项目,将axis 1.4 lib目录下的jar包放到工程的WEB-INF/lib目录下
3.配置web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
<servlet>
<servlet-name>AxisServlet</servlet-name>
<servlet-class>org.apache.axis.transport.http.AxisServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>AxisServlet</servlet-name>
<url-pattern>*.jws</url-pattern>
<url-pattern>/services/*</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
</web-app>
4.开发Service
package axis.example.service;
import java.util.HashMap;
import axis.example.pojo.UserInfo;
public class GetUserInfoService {
private HashMap<String, UserInfo> users = new HashMap<String, UserInfo>();
public GetUserInfoService() {
UserInfo u = new UserInfo();
u.setId(1);
u.setName("AAA");
u.setEmail("AAA@qq.com");
u.setAge(22);
users.put(u.getName(), u);
u.setName("BBB");
u.setEmail("BBB@qq.com");
u.setAge(22);
users.put(u.getName(), u);
}
public UserInfo getUserInfo(String name) {
return users.get(name);
}
}
package axis.example.pojo;
import java.io.Serializable;
public class UserInfo implements Serializable {
private int id;
private String name;
private int age;
private String email;
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
}
5.发布Service
在src目录下创建server-config.wsdd,内容如下
<?xml version="1.0" encoding="UTF-8"?>
<!-- axis webservice config file -->
<deployment xmlns="http://xml.apache.org/axis/wsdd/"
xmlns:java="http://xml.apache.org/axis/wsdd/providers/java">
<handler type="java:org.apache.axis.handlers.http.URLMapper" name="URLMapper"/>
<globalConfiguration>
<!-- 默认为true,改为false后,
客户端如果使用普通http调用方式得到的xml数据中将不会出现multiRef标签 -->
<parameter name="sendMultiRefs" value="false"/>
<!-- 默认为true,改变返回xml数据中不含类型信息 -->
<parameter name="sendXsiTypes" value="false"/>
<!--
<parameter name="enable2DArrayEncoding" value="true"/>
-->
</globalConfiguration>
<service name="GetUserInfoService" provider="java:RPC">
<parameter name="className" value="axis.example.service.GetUserInfoService"/>
<parameter name="allowedMethods" value="getUserInfo"/>
</service>
<transport name="http">
<requestFlow>
<handler type="URLMapper"/>
</requestFlow>
</transport>
</deployment>
6.运行
当使用http://localhost:8088/AxisExample/services/GetUserInfoService?wsdl
访问时得到如下内容,说明发布webservcie成功
7.说明
第一次访问wsdl的时候出现
Unable to find config file. Creating new servlet engine config file: /WEB-INF/server-config.wsdd
不知道是不是因为我没有deploy的时候做一些其他配置,比如我在网上看见还要创建deploy.wsdd,还要tomcat中配置axis。这些我都没有配置,却能够正常调用。不知道是不是版本差异所造成的。