码迷,mamicode.com
首页 > Web开发 > 详细

调用WebService的简单方法

时间:2018-11-02 15:31:40      阅读:227      评论:0      收藏:0      [点我收藏+]

标签:orm   intern   rpc   public   post   static   malformed   ==   java   

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的简单方法

标签:orm   intern   rpc   public   post   static   malformed   ==   java   

原文地址:https://www.cnblogs.com/jinzhiming/p/9896232.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!