調用WebService的簡單方法
阿新 • • 發佈:2018-11-02
pack oca services tms object str bsp nta create
package com.dovepay.webservice.internal.test; import java.net.MalformedURLException; import java.net.URL; import java.rmi.RemoteException; import javax.xml.rpc.ServiceException; import org.apache.axis.client.Call; import org.apache.axis.client.Service; public class T { public staticString callWebService(String serviceUrl,String methodName,String postMsg) { postMsg = (postMsg==null?"":postMsg); URL url = null; String rs = ""; try { url = new URL(serviceUrl); Service service = new Service(); // 通過service創建call對象Call call = (Call) service.createCall(); call.setTargetEndpointAddress(url); call.setOperationName(methodName); Object rsObject = call.invoke(new Object[]{postMsg}); if(rsObject!=null){ rs = (String)rsObject; } }catch (MalformedURLException e) { e.printStackTrace(); } catch (ServiceException e) { e.printStackTrace(); } catch (RemoteException e) { e.printStackTrace(); } return rs; } public static void main(String[] args) { String rs = callWebService("http://localhost:8080/TestService/services/TestWebService?wsdl","doPay", null); System.out.println(rs); } }
調用WebService的簡單方法