0

我在我的 java 代码中使用了一个示例 wsdl。当我尝试打印输出时,它只返回包名,如:

com.holidaywebservice.holidayservice_v2.CountryCode@6b6478

仅当输出为列表时才会发生这种情况。

我的部分代码:

HolidayService2 hs1= new HolidayService2();

HolidayService2Soap hss1=  hs1.getHolidayService2Soap();

ArrayOfCountryCode acc = hss1.getCountriesAvailable();

system.out.println(acc.getCountryCode());

wsdl 网址:http ://holidaywebservice.com/HolidayService_v2/HolidayService2.asmx?WSDL

4

1 回答 1

0

有了这个com.holidaywebservice.holidayservice_v2.CountryCode@6b6478,你试图打印ArrayOfCountryCode对象。您的代码应该是:

package com.holidaywebservice.holidayservice_v2.clientsample;

import com.holidaywebservice.holidayservice_v2.*;

public class ClientSample {

    public static void main(String[] args) {
            //Create Web Service Client..."
            HolidayService2 service1 = new HolidayService2();
            //Create Web Service...
            HolidayService2HttpGet port1 = service1.getHolidayService2HttpGet();

            //call WS
            ArrayOfCountryCode acc =  port1.getCountriesAvailable();
            for(CountryCode cc : acc.getCountryCode()){
                System.out.println("Country code is: " + cc.getCode());
                System.out.println("Country code Description is: " + cc.getDescription());
            }
    }
}


更新尝试仅添加以下内容

for(CountryCode cc : acc.getCountryCode()){
    System.out.println("Country code is: " + cc.getCode());
    System.out.println("Country code Description is: " + cc.getDescription());
}


ArrayOfCountryCode acc = hss1.getCountriesAvailable();在当前代码中 的行之后。但你看到了它的要点,acc是一系列国家代码。

于 2018-10-23T15:23:15.793 回答