1、从官网中下载axis2.war文件,解压缩,获取里面的文件结构,将conf、lib、modules复制到工程中的WEB-INF目录中,axis2-web建议也放到工程WebRoot目录下,因为如果调用webservice失败,没有该文件,系统会报错
2、新建一个类CalculateService
3、修改web.xml
<?xml version=”1.0″ encoding=”UTF-8″?>
<!–增加以下配置–>
</servlet>
</web-app> |
4、在
WEB-INF/新建services目录/建
CalculateService类同名目录(方便阅读)/建META-INF目录/建services.xml文件
如果有多个service服务,则必须用serviceGroup 包含起来
第一种方式: <serviceGroup>
</serviceGroup> |
第二种方式: <serviceGroup>
</serviceGroup> |
5、访问
http://IP:端口/工程名/services/
CalculateServiceFirst
?wsdl
http://IP:端口/工程名/services/
CalculateServiceSecond
?wsdl
访问具体某个方法
http://IP:端口/工程名/services/
CalculateServiceFirst
/方法名称?参数名称=&参数名称=
6、注意
org.apache.axis2.AxisFault: The ServiceClass object does not implement the required method in the following form: OMElement getDocSummary(OMElement e) 原因:在services.xml中没有配置对应的返回值类型:
<messageReceivers> |
|
import org.apache.axis2.AxisFault; import org.apache.axis2.addressing.EndpointReference; import org.apache.axis2.client.Options; import org.apache.axis2.rpc.client.RPCServiceClient;
String endpoint = ”
//调用的方法名称 RPCServiceClient serviceClient = new RPCServiceClient(); Object[] opAddEntryArgs = new Float[] { 1f, 2f }; Class[] classes = new Class[] { Float.class }; // 返回参数类型,这个和axis1有点区别 // invokeBlocking方法有三个参数,其中第一个参数的类型是QName对象,表示要调用的方法名; // 第二个参数表示要调用的WebService方法的参数值,参数类型为Object[]; // 第三个参数表示WebService方法的返回值类型的Class对象,参数类型为Class[]。 // 当方法没有参数时,invokeBlocking方法的第二个参数值不能是null,而要使用new Object[]{} // 如果被调用的WebService方法没有返回值,应使用RPCServiceClient类的invokeRobust方法, // 该方法只有两个参数,它们的含义与invokeBlocking方法的前两个参数的含义相同 Object[] result = serviceClient.invokeBlocking(opAddEntry, opAddEntryArgs, classes); System.out.println(result[0].toString()); |
Axis2生成客户端,调用服务端 |
进入安装目录E:\Apache\axis\axis2-1.6.2\bin,执行
wsdl2java –noBuildXML -uri 详细用法 wsdl2java -help查看 |
AxisServerStub stub = new AxisServerStub(); AxisServerStub.Plus plus = new AxisServerStub.Plus(); plus.setX(1f); plus.setY(1001.2f); PlusResponse plusResponse = stub.plus(plus); System.out.println(plusResponse.get_return()); |
7、集成spring依赖于服务器端接口的方式(待补充)
8、
org.apache.axis2.AxisFault: Namespace URI may not be null
服务端
缺少wstx-asl-3.2.9.jar
9、
|
1,将modules目录下的mar包都拷贝一份到lib下,然后都重新命名扩展名为jar。 2,在发布到websphere上后不要立刻启动这个应用,启动也报错, 需要修改这个应用的管理模块处的类装载顺序,为 本应用优先 |