webService接口调用

本文介绍了如何在Java中调用WebService接口,包括在pom.xml文件中添加依赖以及使用调用工具类的详细步骤。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1.添加pom依赖
<!--axis2 statrt WebService -->
		<dependency>
			<groupId>org.apache.axis2</groupId>
			<artifactId>axis2-adb-codegen</artifactId>
			<version>1.6.2</version>
		</dependency>

		<dependency>
			<groupId>org.apache.axis2</groupId>
			<artifactId>axis2</artifactId>
			<version>1.6.2</version>
			<type>pom</type>
		</dependency>
		<dependency>
			<groupId>org.apache.axis2</groupId>
			<artifactId>axis2-adb</artifactId>
			<version>1.6.2</version>
		</dependency>
		<dependency>
			<groupId>org.apache.axis2</groupId>
			<artifactId>axis2-kernel</artifactId>
			<version>1.6.2</version>
		</dependency>
		<dependency>
			<groupId>org.apache.axis2</groupId>
			<artifactId>axis2-transport-http</artifactId>
			<version>1.6.2</version>
		</dependency>
		<dependency>
			<groupId>org.apache.axis2</groupId>
			<artifactId>axis2-transport-local</artifactId>
			<version>1.6.2</version>
		</dependency>
2、调用工具类
package com.picc.job.utils;

import javax.xml.namespace.QName;

import org.apache.axis2.AxisFault;
import org.apache.axis2.addressing.EndpointReference;
import org.apache.axis2.client.Options;
import org.apache.axis2.rpc.client.RPCServiceClient;

public class WebServiceUtil {

	/**
	 * 
	 * @Desc: webservice 接口请求
	 * @param url        接口地址
	 * @param methodName 方法名称
	 * @param xmlParam   请求参数 请求报文
	 * @return
	 * @throws Exception
	 */
	public static String webSweviceMethod(String url, String methodName, String param) throws AxisFault {
		RPCServiceClient serviceClient = new RPCServiceClient();
		Options options = serviceClient.getOptions();
		options.setTimeOutInMilliSeconds(600*1000);
		options.setProperty(HTTPConstants.SO_TIMEOUT,600*1000);
		EndpointReference targetEPR = new EndpointReference(url);
		options.setTo(targetEPR);

		QName opAddEntry = new QName(url, methodName);

		Object[] opAddEntryArgs = new Object[] { param };

		@SuppressWarnings("rawtypes")
		Class[] classes = new Class[] { String.class };

		return (String) serviceClient.invokeBlocking(opAddEntry, opAddEntryArgs, classes)[0];

	}

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值