Java簡單的調webService接口 – JAVA編程語言程序開發技術文章

/*註意加載xfire-all-1.2.6.jar*/
import org.codehaus.xfire.client.Client; 
/*用dom4j對返回的xml進行解析*/
import org.dom4j.Document; 
import org.dom4j.DocumentException; 
import org.dom4j.Element; 
import org.dom4j.io.SAXReader; 
 
public class Test { 
    public static final String WebService_URL="http://111.11.11.111:8888/desk/service.asmx?wsdl"; 
    public static void main(String[] args) { 
                Client client1 = null; 
                try
                { 
                    client1 = new Client(new URL(WebService_URL)); 
                    Object[] strResult1=null;
                    //如果接口有方法名,且需要帶參數,則在 invoke註明,參數以Object[]數組形式
                    strResult1= client1.invoke("接口方法名", new Object[]{parms1,parms2,…..
                    }); 
                    System.out.println("調接口返回xml格式–>"+strResult1[0]); 
                } 
                catch (MalformedURLException e)  
                { 
                    e.printStackTrace(); 
                }  
                catch (Exception e)  
                { 
                    e.printStackTrace(); 
                } 
    }
}
 
本文出自 “青春行囊” 博客

發佈留言