当前位置: 代码迷 >> Web前端 >> 测试种访问webservice
  详细解决方案

测试种访问webservice

热度:512   发布时间:2012-12-28 10:29:04.0
测试类访问webservice
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.net.MalformedURLException;
import java.rmi.RemoteException;

import javax.xml.parsers.ParserConfigurationException;
import javax.xml.rpc.ServiceException;

import org.apache.axis.client.Call;
import org.apache.axis.client.Service;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.xml.sax.SAXException;

public class SSOLoginTools {
         public static void main(String[] agrs){
	String url = "http://localhost:8080/test/services/BomcAccountFindSercice";
	String method = "queryUsersByPage";
	Integer resID = new Integer("120001");
	String userName = "test";
	String signature = "test";
	Object[] objects = new Object[]{resID,userName,signature};
	
	try {
		Service service = new Service();
		Call call = (Call) service.createCall();
		call.setTargetEndpointAddress(new java.net.URL(url));
		call.setOperationName(method);
		call.addParameter("resID", org.apache.axis.encoding.XMLType.XSD_STRING,
				javax.xml.rpc.ParameterMode.IN);
		call.addParameter("userName", org.apache.axis.encoding.XMLType.XSD_STRING,
				javax.xml.rpc.ParameterMode.IN);
		call.addParameter("signature", org.apache.axis.encoding.XMLType.XSD_STRING,
				javax.xml.rpc.ParameterMode.IN);
		call.setReturnType(org.apache.axis.Constants.XSD_STRING);
		String ret = (String)call.invoke(objects);
		System.out.println("ret="+ret);
	} catch (MalformedURLException e) {
		e.printStackTrace();
	} catch (RemoteException e) {
		e.printStackTrace();
	} catch (ServiceException e) {
		e.printStackTrace();
	} catch (UnsupportedEncodingException e) {
		e.printStackTrace();
	} catch (ParserConfigurationException e) {
		e.printStackTrace();
	} catch (SAXException e) {
		e.printStackTrace();
	} catch (IOException e) {
		e.printStackTrace();
	}	
      }
}

?

  相关解决方案