import java.util.Map;
import java.util.Vector;
import java.util.Iterator;
import java.util.Arrays;
import org.apache.axis.wsdl.symbolTable.*;
public class wsCaller {
/**
* @param args
*/
public static void main(String[] args) {
String wsdlLocation =
"http://192.168.1.113/ReadOffice/ReadWord.asmx?wsdl";
String serviceName = "ReadWord";
String operationName = "read";
String strFirstParam = "c:\\nlb.log";
String strSecondParam = "0";
String strThirdParam = "200";
String portName = "ReadWordSoap";
/*
* 添加web service方法的输入参数到Vector
*/
Vector parameterValues = new Vector();
parameterValues.addElement(strFirstParam);
parameterValues.addElement(strSecondParam);
parameterValues.addElement(strThirdParam);
try
{
DynamicInvoker invoker = new DynamicInvoker(wsdlLocation);
/*
* 遍历web service每一个方法,获取serverName、参数列表以及类型的过程
*/
Vector vServices = invoker.enumServiceNames();
Object[] Services = vServices.toArray();
Arrays.sort(Services);
for (int i = 0; i < Services.length; i++)
{
String strServiceName = (String) Services[i];
System.out.println("ServiceName=" + serviceName);
Vector V = invoker.enumPortNames(strServiceName);
String strPortName = (String) V.elementAt(0);
System.out.println("PortName=" + strPortName);
V = invoker.enumOperationNames(strServiceName, strPortName);
Object[] OperationNames = V.toArray();
Arrays.sort(OperationNames);
for (int j = 0; j < OperationNames.length; j++)
{
String strOperationName = (String) OperationNames[j];
System.out.println("\t" + (String) OperationNames[j]);
Parameters parameters = invoker.enumParameters(strServiceName, strPortName, strOperationName);
Vector v = parameters.list;
Vector vParameterValues = new Vector();
for (int k = 0; k < v.size(); k++)
{
Parameter para = (Parameter) v.elementAt(k);
System.out.print("\t\t" + para.getQName().getLocalPart());
if (para.getType().getQName().getLocalPart().equals("string"))
{
vParameterValues.addElement("asdasdas");
}
else
{
vParameterValues.addElement(null);
}
System.out.print("\t" + para.getType().getQName().getLocalPart());
System.out.println("\t" + invoker.getParameterModeString(para));
}
}
}
// 最后一个参数是调用web service的超时时间,这个原来是固化在类里面的
// 但其实应该暴露出来
Map map = invoker.invoke(serviceName,
portName, operationName, parameterValues,
new Integer(60 * 1000));
// print result
System.out.println("Result:");
for (Iterator it = map.keySet().iterator(); it.hasNext();)
{
String name = (String) it.next();
System.out.println(name + "=" + map.get(name));
}
System.out.println("\nDone!");
}
catch (Exception exc) {
exc.printStackTrace();
}
}
}
|
请发表评论