eclipse生成并调用webservices客户端client

1.在想要生成webservices客户端的项目上右键->new->other->webservice client

2.填写webservices服务的发布地址(带有?wsdl)->next->finash

生成的客户端代码如下

     

3.以上两种生成的客户端代码略有不同(可能是版本的问题),但基本原理都是一样的,所以就两个类型的代码分别做调用

  (1)调用代码如下

package ticket;

import java.util.List;




import com.crs.ticket.wanda.ticket.service.Student;
import com.crs.ticket.wanda.ticket.service.TicketServicesServiceLocator;
import com.crs.ticket.wanda.ticket.service.TicketServicesServiceSoapBindingStub;


public class ticket {
    private static TicketServicesServiceLocator initWebServiceURL() throws Exception{
        
        TicketServicesServiceLocator locator = new TicketServicesServiceLocator();
        
        locator.setticketServicesPortEndpointAddress("http://192.168.16.151:8085/cxf_spring_service/services/ticket"); 
        return locator;
    }

    public static void main(String[] args) {
        String studentNo = "01";
        TicketServicesServiceLocator locator;
        try {
            locator = initWebServiceURL();
            TicketServicesServiceSoapBindingStub stub = (TicketServicesServiceSoapBindingStub) locator.getticketServicesPort();
            Student[] students = stub.findStudentInfoByStudNo(studentNo);
            System.out.println(students[0].getSname());
        } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        
    }
}

  (2)调用代码如下

try{
            //BookingTicketsLocator locator = new BookingTicketsLocator();
            BookingTicketsLocator locator = initWebServiceURL(idCompany);
            String json = locator.getBookingTicketsSoap().getPerformances(
                    startTime, endTime, reservedAreaId,repertoireID);
            if (StringUtils.isNotBlank(json)) {
                result = JSON.parseObject(json, JWebServiceResult.class);
            }
            logger.info(json);
        } catch (HasNotShowException e){
            result = new JWebServiceResult();
            result.setISSuccess(1);
            result.setResultData(new ArrayList<JPerformanceWsdl>());
        }
        return result;

 

转载于:https://www.cnblogs.com/pypua/articles/7110234.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值