使用XFire对于带参,并返回集合对象的WebService进行动态调用

package com;

import java.net.URL;

import org.codehaus.xfire.client.Client;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;

public class ws {

	/**
	 * 使用XFire对于带参,并返回集合对象的WebService进行调用
	 */
	public static void main(String[] args) {

		try {
			//构建XFire的动态客户端
			Client client = new Client(new URL("http://10.1.42.135:8080/domo/services/QyService?wsdl"));
			//通过反射动态调用方法,并带入参数
			Object[] results = client.invoke("getQyListByhms", new Object[] {"01","310227194407241028","1","1"});
			
			//遍历返回的 List<Object> 集合对象
			for(int i=0;i<results.length;i++){
				Element element = ((Document)results[i]).getDocumentElement();
				
				//使用Dom解析Object
				NodeList children = element.getChildNodes(); 
				for (int j = 0; j < children.getLength(); j++) { 
				   Node node = children.item(j); 
				   
				   System.out.println("NodeName:" + node.getNodeName()); 
				   System.out.println("tNodeValue:" + node.getTextContent()); 
				   System.out.println();
				   
				   //使用Dom解析对象属性
				   for (Node child = node.getFirstChild(); child!= null; child = child.getNextSibling()) { 
					   if(child instanceof Node)// 去除多余的空白 
					   { 
						   System.out.println("NodeName:" + child.getNodeName()); 
						   System.out.println("tNodeValue:" + child.getTextContent()); 
						   System.out.println();
						} 
					}
				} 
			}
			
		} catch (Exception e) {
			System.out.println("#Error ["+e.getMessage()+"] ");
		}

	}

}

你可能感兴趣的:(webservice,xfire)