JAVA动态调用C#WebService客户端

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/qq_33335577/article/details/78006334

使用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>

猜你喜欢

转载自blog.csdn.net/qq_33335577/article/details/78006334
今日推荐