java调用WebService

原创
2016/09/08 11:59
阅读数 336

Java调用.net的WebService,因为对WebService不熟悉,搞了一天,终于搞完

package com.pansoft.jbsf.oa.controller;

import java.rmi.RemoteException;
import java.util.ArrayList;
import java.util.List;

import javax.xml.namespace.QName;
import javax.xml.rpc.ServiceException;

import org.apache.axis.client.Call;
import org.apache.axis.client.Service;

import com.jf.core.Controller;
import com.pansoft.jbsf.bean.JsonResult;
import com.pansoft.oa.untils.BussinessUtils;

import net.sf.json.JSONObject;

public class SSOLoginController extends  Controller{
	
	public String getCurrentUserId(){
		Object object = this.getRequest().getSession().getAttribute("usercode");//不能为空
		if(object!=null){
			return object.toString();
		}else{
			return "";
		}
	}
	/**
	 * 默认
	 * @throws Exception 
	 * */
	public void index() throws Exception{
		GetAuthenticationUser();
	}
	/**
	 * 获取单点登录用户Token 
	 * 解析用户信息
	 * 判断用户是否存在
	 * */
	public void GetAuthenticationUser() throws org.apache.soap.SOAPException, ServiceException, RemoteException{
		JsonResult result = new JsonResult();
		String Token = getPara("Token");
		JSONObject object = JSONObject.fromObject(Token);
		String token = object.getString("Token");
		String endpoint = "http://10.16.1.1/portal/sso.asmx";
		Service service = new Service();
		Call call = (Call) service.createCall();
		call.setOperationName(new QName("http://tempuri.org/","GetAuthenticationUser"));
		call.setTargetEndpointAddress(endpoint);
		call.setEncodingStyle("UTF-8");
		call.setUseSOAPAction(true);
		call.setSOAPActionURI("http://tempuri.org/GetAuthenticationUser");
		call.addParameter("SystemCode", org.apache.axis.encoding.XMLType.XSD_STRING,javax.xml.rpc.ParameterMode.IN);//接口的参数
		call.addParameter("Secret", org.apache.axis.encoding.XMLType.XSD_STRING,javax.xml.rpc.ParameterMode.IN);//接口的参数
		call.addParameter("Token", org.apache.axis.encoding.XMLType.XSD_STRING,javax.xml.rpc.ParameterMode.IN);//接口的参数
		call.setReturnType(org.apache.axis.encoding.XMLType.XSD_STRING);//设置返回类型 
		String username = (String)call.invoke(new Object[]{"ZHXZFWPT","",token});
		if(BussinessUtils.ifhavaUser(username)){//判读系统是否有该用户
			result.setSuccess(true);
			result.setData(username);
		}else{
			result.setSuccess(false);
			List<String> message = new ArrayList<String>();
			message.add("单点登录用户不存在!");
			result.setMessage(message);
		}
		//给方法传递参数,并且调用方法
		renderJson(result);
	}

}

 

注意命名空间是      http://tempuri.org

方法名是                 GetAuthenticationUser

服务地址是              http://10.16.1.1/portal/sso.asmx

SOAPActionURI是           http://tempuri.org/GetAuthenticationUser

 

【SOAPActionURI】为啥是这个我也不懂~

展开阅读全文
加载中
点击引领话题📣 发布并加入讨论🔥
0 评论
0 收藏
1
分享
返回顶部
顶部