我如何webservicex.net
实际get the weather?
thufir@dur:~/NetBeansProjects/javaClientGlobalWeather$
thufir@dur:~/NetBeansProjects/javaClientGlobalWeather$ gradle clean shadowJar;java -jar build/libs/weather.jar
> Task :shadowJar
A problem was found with the configuration of task ':shadowJar'. Registering invalid inputs and outputs via TaskInputs and TaskOutputs methods has been deprecated and is scheduled to be removed in Gradle 5.0.
- No value has been specified for property 'mainClassName'.
The SimpleWorkResult type has been deprecated and is scheduled to be removed in Gradle 5.0. Please use WorkResults.didWork() instead.
BUILD SUCCESSFUL in 2s
3 actionable tasks: 3 executed
Feb 16, 2018 2:42:10 AM net.bounceme.dur.java.soap.weather.App run
INFO: begin
Feb 16, 2018 2:42:11 AM net.bounceme.dur.java.soap.weather.Weather getWeather
INFO: Data Not Found
thufir@dur:~/NetBeansProjects/javaClientGlobalWeather$
java code:
package net.bounceme.dur.java.soap.weather;
import java.util.logging.Logger;
import net.webservicex.GetCitiesByCountry;
import net.webservicex.GetWeather;
import net.webservicex.GetWeatherResponse;
import net.webservicex.GlobalWeather;
import net.webservicex.GlobalWeatherSoap;
import net.webservicex.ObjectFactory;
public class Weather {
private static final Logger log = Logger.getLogger(App.class.getName());
public void getWeather(String country, String city) {
GlobalWeather gw = new GlobalWeather();
GlobalWeatherSoap gws = gw.getGlobalWeatherSoap();
String w = gws.getWeather(city, country);
log.info(w);
}
public void getWeather3(String country, String city) {
ObjectFactory o = new ObjectFactory();
GetWeather gw = o.createGetWeather();
gw.setCountryName(country);
gw.setCityName(city);
GetWeatherResponse gwr = o.createGetWeatherResponse();
gwr.setGetWeatherResult(city);
String r = gwr.getGetWeatherResult();
log.info(r);
}
public void getWeather2(String country, String city) {
log.info("getting weather");
GetCitiesByCountry g = new GetCitiesByCountry();
g.setCountryName(country);
log.fine(g.getCountryName());
GetWeather getWeather = new GetWeather();
getWeather.setCountryName(country);
getWeather.setCityName(city);
log.fine(getWeather.getCountryName());
log.fine(getWeather.getCityName());
log.info(getWeather.toString());
GetWeatherResponse weatherResponse = new GetWeatherResponse();
log.info("weather response result:\t" + weatherResponse.getGetWeatherResult());
log.info("end");
}
}
存根由wsimport http://www.webservicex.net/globalweather.asmx?WSDL -Xnocompile
生成。查看生成的类,不确定如何实际使用Java中的this service。
是否需要将WSDL传递给GlobalWeather
或GlobalWeatherSoap
?这很奇怪,因为它们是用wsimport
生成的。这只是知道如何阅读WSDL
?
另见: