WebService自说自话-提供一个Class类作为服务端加测试的例子(Axis2实现)

1、导入包!

服务端

2、写好一个JavaClass的例子

a、写好pojo类

User类

package com.bean;

public class User
{
    private String userName;
    
    public String getUserName()
    {
        return userName;
    }
    
    public void setUserName(String userName)
    {
        this.userName = userName;
    }
}

 

b、写好普通服务的类

UserQuery类

package com;

import com.bean.User;

public class UserQuery
{
    public User getUserInfo(String userName)
    {
        User us = new User();
        us.setUserName(userName);
        System.out.println("================ " + userName);
        return us;
    }
}

 其中public User getUserInfo(String userName)就是提供的方法

3、根据规则建好目录

a、在WEB-INF目录底下新建services目录

b、在services目录下根据需求新建一个目录作为放webservice的服务描述文件目录随便取个就成[xxx吧]

c、在xxx下新建META-INF目录(必须的)

d、MANIFEST.MF文件

Manifest-Version: 1.0
Class-Path: 

e、services.xml

<?xml version="1.0" encoding="UTF-8"?>
<serviceGroup>
	<service name="query">
		<parameter name="ServiceClass">
			com.UserQuery
		</parameter>
		<parameter name="useOriginalwsdl">false</parameter>
		<parameter name="modifyUserWSDLPortAddress">true</parameter>
		
		<messageReceivers>
			<messageReceiver
				mep="http://www.w3.org/2004/08/wsdl/in-only"
				class="org.apache.axis2.rpc.receivers.RPCInOnlyMessageReceiver" />

			<messageReceiver mep="http://www.w3.org/2004/08/wsdl/in-out"
				class="org.apache.axis2.rpc.receivers.RPCMessageReceiver" />
		</messageReceivers>
	</service>
</serviceGroup>

4、发布、访问该服务

a、web.xml中配置好需要的servlet

   <servlet>
  	<servlet-name>AxisServlet</servlet-name>
  	<servlet-class>
  		org.apache.axis2.transport.http.AxisServlet
  	</servlet-class>
  </servlet>

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

 

b、发布服务,在tomcat中部署好该应用

c、访问

查看wsdl
http://localhost:8080/ws/services/query?wsdl

 

客户端

5、下载wsdl文件

 

6、根据wsdl文件生成客户端需要的代码

7、完成客户端调用

 

未完待续

你可能感兴趣的:(apache,tomcat,bean,webservice,servlet)