JAVA动态调用C#WebService客户端

使用Axis框架动态调用,下面是JAVA代码


import java.rmi.RemoteException;
import javax.xml.namespace.QName;
import javax.xml.rpc.ParameterMode;
import javax.xml.rpc.ServiceException;
import javax.xml.rpc.encoding.XMLType;
import org.apache.axis.client.Call;
import org.apache.axis.client.Service;

/**
 * JAVA Axis框架 动态调用C# WebService客户端
 * @author 黄泽群
 * @version 2017年9月15日
 */
public class AxisWebServiceClient {
	public void test() {
		String url = "http://127.0.0.1:8063/Service.asmx";
		String namespace = "http://tempuri.org/";
		String methodName = "OpRecipeQuery";
		String soapActionURI = "http://tempuri.org/OpRecipeQuery";
		Service service = new Service();
		Call call;
		try {
			call = (Call) service.createCall();
			call.setTargetEndpointAddress(url);
			call.setUseSOAPAction(true);
			call.setSOAPActionURI(soapActionURI); // 设置远程调用的方法
			call.setOperationName(new QName(namespace, methodName)); // 设置远程调用的参数
			call.addParameter(new QName(namespace, "request"), XMLType.XSD_STRING, ParameterMode.IN); // 设置返回类型
			call.setReturnType(XMLType.XSD_STRING); // 获取提交的报文
			Object obj = call.invoke(new Object[] { "你好!我是客户端" });
			System.out.println(obj);
		} catch (ServiceException e) {
			e.printStackTrace();
		} catch (RemoteException e) {
			e.printStackTrace();
		}
	}

	public static void main(String[] args) {
		new AxisWebServiceClient().test();
	}
}

Maven依赖

 

	    Mavem依赖
			<dependency>
			    <groupId>axis</groupId>
			    <artifactId>axis</artifactId>
			    <version>1.4</version>
			</dependency>

 

 

 

 

 

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值