Java 调用C#Webservice 封装

1、代码

import java.net.URL;
import javax.xml.namespace.QName;
import org.apache.axis.client.Call;
import org.apache.axis.client.Service;

public class WebServiceUtil {
	/**
	 * 
	 * @param serviceUrl 服务名
	 * @param nameSpace
	 * @param methodName 执行的方法名
	 * @param paremateArrs 参数数据数组
	 * @param qNameArrs 变量数组
	 * @return
	 */
	public static Object CallSoapService(String serviceUrl ,String nameSpace,String methodName, Object[] paremateArrs,Object[]  qNameArrs){
		String endPoint = serviceUrl;
		String actionUrl=nameSpace+methodName;
		Object returnObj = null;
		try{
			Service service = new Service();
			Call call = null;
			call = (Call)service.createCall();

			QName qName = new QName(nameSpace,methodName); 
			call.setOperationName(qName);
			call.setSOAPActionURI(actionUrl);
			
			for(int i=0,len=qNameArrs.length;i<len;i++){
				 call.addParameter(new QName(nameSpace,qNameArrs[i].toString()), org.apache.axis.encoding.XMLType.XSD_STRING,
						javax.xml.rpc.ParameterMode.IN); 
			}
			call.setReturnType(org.apache.axis.encoding.XMLType.XSD_STRING);
			call.setTargetEndpointAddress(new URL(endPoint)); 
			returnObj = call.invoke(paremateArrs);
			
		}catch(Exception ie){
			ie.printStackTrace();
		}
		System.out.println(returnObj);
		return returnObj;
	}

	public static void main(String[] args) {
		String url="http://webservice.webxml.com.cn/WebServices/MobileCodeWS.asmx";
		String method="getMobileCodeInfo";
		String parameter="15170560850";
		String namespace="http://WebXml.com.cn/";
		WebServiceUtil.CallSoapService(url,namespace,method,new Object[]{parameter,""},new Object[]{"mobileCode","userID"});
 	
	}
	
}

2、在线接口
2)方法名 getMobileCodeInfo
3)命名空间为下图2


调用实例:http://download.csdn.net/detail/luckytjx/7994089




                
  • 1
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值