调用跨系统接口(本地java,对方.net,参数里的pramat为xml格式)

本文介绍了一个使用Java调用.NET WebService的具体实例,包括配置Axis客户端和服务端的过程,以及如何设置SOAPActionURI等关键步骤。

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

package com.foxera.util;

	import javax.xml.namespace.QName;

	import org.apache.axis.client.Call;
	import org.apache.axis.client.Service;
	import org.apache.axis.encoding.XMLType;
	import org.slf4j.Logger;
	import org.slf4j.LoggerFactory;

	public class WebServiceProxy {
		private static Logger logger = LoggerFactory
				.getLogger(WebServiceProxy.class);

		public String CallService(String pramat, String salesOrderNum) {
			Object result = null;
			String ecsResult = null;
			try {
                                // 127.0.0.1 为.net webService 地址
				String url = "http://127.0.0.1/ECS_EMMS_REQUEST/Service1.asmx";
				// .net webService 命名空间
				String namespace = "http://tempuri.org/";
				// .net webService 需调用的方法
				String methodName = "FeeAdd";
				String soapActionURI = "http://tempuri.org/FeeAdd";
				Service service = new Service();

				Call call = (Call) service.createCall();

				call.setTargetEndpointAddress(new java.net.URL(url));
				call.setUseSOAPAction(true);
				// 这个地方没设对就会出现Server was unable to read request的错误
				call.setSOAPActionURI(soapActionURI);
				// 设置要调用的.net webService方法
				call.setOperationName(new QName(namespace, methodName));
				// 设置该方法的参数,temp为.net webService中的参数名称
				call.addParameter(new QName(namespace, "xmlString"),
						org.apache.axis.encoding.XMLType.XSD_STRING,
						javax.xml.rpc.ParameterMode.IN);
				// 设置该方法的返回值
				call.setReturnType(XMLType.XSD_STRING);
				// call.invoke(new Object[] { "kusix" }); 中"kusix"为传入参数值
				ecsResult = (String) call.invoke(new Object[] { pramat });
				System.out.println("返回结果---> " + ecsResult);
				return ecsResult;
			}

			catch (Exception e) {
				logger.error("调用ECS接口失败:" + salesOrderNum + "," + ecsResult + ","
						+ e.getMessage());
				System.err.println(e.toString());

			}

			return ecsResult;
		}

	}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值