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;

 

posted @ 2017-07-03 11:26  十月围城小童鞋  阅读(485)  评论(0编辑  收藏  举报