axis2 以 RPC的方式访问webservice

1、下载axis2 相关包了,


http://axis.apache.org/axis2/java/core/download.html

首先下载

 

axis2-1.7.1-bin.zip

这里包含所有要用到的包

其次就是下载 自带的服务程序

axis2-1.7.1-war.zip

这里面就是个javaweb程序,解压后把war包放到tomcat下的webapp下,启动tomcat就行了

可以访问看看效果


点击Services        

点击Version 可以看到wsdl文件的内容了

<?xml version="1.0" encoding="UTF-8"?>

<wsdl:definitions targetNamespace="http://axisversion.sample" xmlns:wsaw="http://www.w3.org/2006/05/addressing/wsdl" xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/" xmlns:http="http://schemas.xmlsoap.org/wsdl/http/" xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:ns="http://axisversion.sample" xmlns:ns1="http://org.apache.axis2/xsd" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"><wsdl:documentation>Version</wsdl:documentation><wsdl:types><xs:schema targetNamespace="http://axisversion.sample" elementFormDefault="qualified" attributeFormDefault="qualified"><xs:element name="VersionException"><xs:complexType><xs:sequence><xs:element type="ns:Exception" name="VersionException" nillable="true" minOccurs="0"/></xs:sequence></xs:complexType></xs:element><xs:complexType name="Exception"><xs:sequence><xs:element type="xs:string" name="Message" nillable="true" minOccurs="0"/></xs:sequence></xs:complexType><xs:element name="getVersion"><xs:complexType><xs:sequence/></xs:complexType></xs:element><xs:element name="getVersionResponse"><xs:complexType><xs:sequence><xs:element type="xs:string" name="return" nillable="true" minOccurs="0"/></xs:sequence></xs:complexType></xs:element></xs:schema></wsdl:types><wsdl:message name="getVersionRequest"><wsdl:part name="parameters" element="ns:getVersion"/></wsdl:message><wsdl:message name="getVersionResponse"><wsdl:part name="parameters" element="ns:getVersionResponse"/></wsdl:message><wsdl:message name="VersionException"><wsdl:part name="parameters" element="ns:VersionException"/></wsdl:message><wsdl:portType name="VersionPortType"><wsdl:operation name="getVersion"><wsdl:input wsaw:Action="urn:getVersion" message="ns:getVersionRequest"/><wsdl:output wsaw:Action="urn:getVersionResponse" message="ns:getVersionResponse"/><wsdl:fault name="VersionException" wsaw:Action="urn:getVersionVersionException" message="ns:VersionException"/></wsdl:operation></wsdl:portType><wsdl:binding type="ns:VersionPortType" name="VersionSoap11Binding"><soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/><wsdl:operation name="getVersion"><soap:operation style="document" soapAction="urn:getVersion"/><wsdl:input><soap:body use="literal"/></wsdl:input><wsdl:output><soap:body use="literal"/></wsdl:output><wsdl:fault name="VersionException"><soap:fault name="VersionException" use="literal"/></wsdl:fault></wsdl:operation></wsdl:binding><wsdl:binding type="ns:VersionPortType" name="VersionSoap12Binding"><soap12:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/><wsdl:operation name="getVersion"><soap12:operation style="document" soapAction="urn:getVersion"/><wsdl:input><soap12:body use="literal"/></wsdl:input><wsdl:output><soap12:body use="literal"/></wsdl:output><wsdl:fault name="VersionException"><soap12:fault name="VersionException" use="literal"/></wsdl:fault></wsdl:operation></wsdl:binding><wsdl:binding type="ns:VersionPortType" name="VersionHttpBinding"><http:binding verb="POST"/><wsdl:operation name="getVersion"><http:operation location="getVersion"/><wsdl:input><mime:content type="application/xml" part="parameters"/></wsdl:input><wsdl:output><mime:content type="application/xml" part="parameters"/></wsdl:output><wsdl:fault name="VersionException"/></wsdl:operation></wsdl:binding><wsdl:service name="Version"><wsdl:port name="VersionHttpSoap11Endpoint" binding="ns:VersionSoap11Binding"><soap:address location="http://localhost:88/axis2/services/Version.VersionHttpSoap11Endpoint/"/></wsdl:port><wsdl:port name="VersionHttpSoap12Endpoint" binding="ns:VersionSoap12Binding"><soap12:address location="http://localhost:88/axis2/services/Version.VersionHttpSoap12Endpoint/"/></wsdl:port><wsdl:port name="VersionHttpEndpoint" binding="ns:VersionHttpBinding"><http:address location="http://localhost:88/axis2/services/Version.VersionHttpEndpoint/"/></wsdl:port></wsdl:service></wsdl:definitions>


下面是client端需要的jar包


下面是测试代码

public static String getResource(String qqbw) throws Exception{
  String jgbw = "";
  try {

   String wsUrl = "http://localhost:88/axis2/services/Version/getVersion?wsdl";
   //使用RPC方式调用WebService
   RPCServiceClient serviceClient = new RPCServiceClient();
   Options options = serviceClient.getOptions();
   //设置2秒超时
   options.setTimeOutInMilliSeconds(2000L);
   //指定调用WebService的URL
   EndpointReference targetEPR = new EndpointReference(wsUrl);
   options.setTo(targetEPR);
   
   //指定接口方法的参数值
   Object[] opAddEntryArgs = new Object[] {qqbw};
   //指定方法返回值的数据类型的Class对象
   Class[] classes = new Class[] { String.class };
   //指定调用的方法及WSDL文件的命名空间
   QName opAddEntry = new QName(
     "http://axisversion.sample",
     "getVersioin");
   //调用getVersioin方法并输出该方法的返回值,
   //返回对象是一个Object的数组,拿数组的第一个值,转换强转即可
   jgbw = serviceClient.invokeBlocking(opAddEntry,
                 opAddEntryArgs, classes)[0].toString();
  } catch (Exception e) {
   e.printStackTrace();
   jgbw = e.getMessage();
  }
  
  return jgbw;
 }




  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值