---
title: "测试类访问webservice"
author: "duyunfengsolo"
date: "2010-12-25T11:05:03Z"
tags: []
categories: ["编程语言"]
slug: "webservice"
draft: false
lastmod: "2010-12-25T11:05:03Z"
id: 851651
url: "https://solodu.iteye.com/blog/851651"
---

```
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();
	}	
      }
}
```