首页 > 解决方案 > SOAP:如何在 Java 中调用 CountryInfoService WSDL 文件,例如使用 CapitalCity SOAP 操作

问题描述

您好,我设法使用带有“ wsimport ”命令的 Java-WS 生成 WSDL Java 类。WSDL 文件来自:

http://webservices.oorsprong.org/websamples.countryinfo/CountryInfoService.wso?wsdl

在此处输入图像描述

问题是我不熟悉如何使用它。如何对 CapitalCity SOAP 方法进行 SOAP 调用。

在 SOAPUI 中,您只需传递 CountryISOCode,如下所示:

xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:web="http://www.oorsprong.org/websamples.countryinfo">
   <soapenv:Header/>
   <soapenv:Body>
      <web:CapitalCity>
         <web:sCountryISOCode>UKR</web:sCountryISOCode>
      </web:CapitalCity>
   </soapenv:Body>
</soapenv:Envelope>

如何在 Java 中做到这一点?这是我开始的代码。

CountryInfoService countryInfoService = new CountryInfoService();

我不知道接下来会发生什么。我再次尝试使用“ CapitalCity ”SOAP 操作。

标签: javaapiweb-servicessoapsoap-client

解决方案


这是一个示例答案:

    CountryInfoService countryInfoService = new CountryInfoService();
    CountryInfoServiceSoapType countryInfoServiceSoapType = countryInfoService.getCountryInfoServiceSoap();
    System.out.println(countryInfoServiceSoapType.capitalCity("RUS"));
    //output is 'Moscow'

这就是如何使用它。


推荐阅读