Primeramente Abrimos Netbeans y creamos un proyecto Java(El mismo ejemplo lo podriamos hacer desde una aplicacion web). Esta aplicación la llamamos como WSClient.

Damos click derecho sobre el proyecto y Seleccionamos la categoria Web Services y en File Types Seleccionamos Web Service Client, damos click sobre Next

En la siguiente pantalla marcamos WSDL URL y colocamos la siguiente URL:
http://www.webservicex.net/globalweather.asmx?wsdl y damos click en Finish(Dejamos el estilo del cliente como JAX-WS Client).
Una vez hecho esto, en el lado izquierdo veremos el recurso GlobalWeather dentro de Web Service References.

Ahora, dentro de public static void main, de Main.java damos boton derecho y seleccionamos la opción "Web Service Cliente Resorce" y damos click en "call web service operation". Se nos abre una ventana con los diferentes métodos del Web Service de Global Weather.

Seleccionamos GetWeather y damos click en OK
y nos agrega el siguiente código
try { // Call Web Service Operation
net.webservicex.GlobalWeather service = new net.webservicex.GlobalWeather();
net.webservicex.GlobalWeatherSoap port = service.getGlobalWeatherSoap();
// TODO initialize WS operation arguments here
java.lang.String cityName = "Quito";
java.lang.String countryName = "Ecuador";
// TODO process result here
java.lang.String result = port.getWeather(cityName, countryName);
System.out.println("Result = " + result);
} catch (Exception ex) {
// TODO handle custom exceptions here
}
Podemos cambiar las variables cityName y countryName a Quito y Ecuador respectivamente y ejecutar el aplicativo, con lo cual tenemos una salida como esta:
Result =
No hay comentarios:
Publicar un comentario