调用WebService的简单方法
Posted 新手娃娃菜
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了调用WebService的简单方法相关的知识,希望对你有一定的参考价值。
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 static String 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的简单方法的主要内容,如果未能解决你的问题,请参考以下文章
如何用webservice从客户端发送一个xml给服务端接收并插入数据库