加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

Axis2调用WebService

发布时间:2020-12-16 21:58:35 所属栏目:安全 来源:网络整理
导读:? ? ? ?本例使用的版本为是Axis2-1.5.4。需要引入如下jar包。 ?/lib/axiom-api-1.2.10.jar ?/lib/axiom-impl-1.2.10.jar /lib/axis2-adb-1.5.4.jar ?/lib/axis2-kernel-1.5.4.jar ?/lib/axis2-transport-http-1.5.4.jar ?/lib/axis2-transport-local-1.5.4.j

? ? ? ?本例使用的版本为是Axis2-1.5.4。需要引入如下jar包。

?/lib/axiom-api-1.2.10.jar

?/lib/axiom-impl-1.2.10.jar

/lib/axis2-adb-1.5.4.jar

?/lib/axis2-kernel-1.5.4.jar

?/lib/axis2-transport-http-1.5.4.jar

?/lib/axis2-transport-local-1.5.4.jar

?/lib/commons-codec-1.3.jar

?/lib/commons-httpclient-3.1.jar

?/lib/commons-logging-1.1.3.jar

?/lib/wsdl4j-1.6.2.jar

?/lib/XmlSchema-1.4.3.jar

?/lib/neethi-2.0.4.jar

?/lib/mail-1.4.jar

?/lib/httpcore-4.0.jar

? ? ? ? 本例使用的远程Web服务为,天气预报服务:http://www.webxml.com.cn/WebServices/WeatherWebService.asmx。案例演示的调用的方法为getSupportCity,查询本天气预报Web Services支持的国内外城市或地区信息。

输入参数:byProvinceName = 指定的洲或国内的省份,若为ALL或空则表示返回全部城市;

返回数据:一个一维字符串数组 String(),结构为:城市名称(城市代码)。

? ? ? ?具体操作创建RPCClient

public class RPCClient {

	public static void main(String[] args) {
		
		try {
			//使用RPC方式调用WebService
			RPCServiceClient rpcServiceClient = new RPCServiceClient();
			Options options = rpcServiceClient.getOptions();
			
			//指定调用WebService的URL
			String address = "http://www.webxml.com.cn/WebServices/WeatherWebService.asmx";
			EndpointReference targetEndpoint = new EndpointReference(address);
			options.setAction("http://WebXml.com.cn/getSupportCity");
			options.setTo(targetEndpoint);
			// 如果报错提示Content-Length,请求内容长度 
			options.setProperty(HTTPConstants.CHUNKED,"false");
			
			//指定要调用的getSupportCity方法及WSDL文件的命名空间
			OMFactory omFactory = OMAbstractFactory.getOMFactory();
			OMNamespace omNamespace = omFactory.createOMNamespace("http://WebXml.com.cn/","");
			OMElement method = omFactory.createOMElement("getSupportCity",omNamespace);
			OMElement param = omFactory.createOMElement("byProvinceName",omNamespace);
			
			//指定getSupportCity方法的参数值
			param.setText("ALL");
			method.addChild(param);
			OMElement result = rpcServiceClient.sendReceive(method);
			
			System.out.println(result.toString());
			
		} catch (AxisFault e) {
			e.printStackTrace();
		}
	}

所需jar的下载地址为:点击下载

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读