I am trying to connect to a weather API.
The class was created from wsdl2apex
public class AsyncWeatherRequestWebService2 {
public class GetCitiesByCountryResponse_elementFuture extends System.WebServiceCalloutFuture {
public String getValue() {
WeatherRequestWebService2.GetCitiesByCountryResponse_element response = (WeatherRequestWebService2.GetCitiesByCountryResponse_element)System.WebServiceCallout.endInvoke(this);
return response.GetCitiesByCountryResult;
}
}
public class GetWeatherResponse_elementFuture extends System.WebServiceCalloutFuture {
public String getValue() {
WeatherRequestWebService2.GetWeatherResponse_element response = (WeatherRequestWebService2.GetWeatherResponse_element)System.WebServiceCallout.endInvoke(this);
return response.GetWeatherResult;
}
}
public class AsyncGlobalWeatherSoap {
public String endpoint_x = 'http://www.webservicex.net/globalweather.asmx';
public Map<String,String> inputHttpHeaders_x;
public String clientCertName_x;
public Integer timeout_x;
private String[] ns_map_type_info = new String[]{'http://www.webserviceX.NET', 'WeatherRequestWebService2'};
public AsyncWeatherRequestWebService2.GetCitiesByCountryResponse_elementFuture beginGetCitiesByCountry(System.Continuation continuation,String CountryName) {
WeatherRequestWebService2.GetCitiesByCountry_element request_x = new WeatherRequestWebService2.GetCitiesByCountry_element();
request_x.CountryName = CountryName;
return (AsyncWeatherRequestWebService2.GetCitiesByCountryResponse_elementFuture) System.WebServiceCallout.beginInvoke(
this,
request_x,
AsyncWeatherRequestWebService2.GetCitiesByCountryResponse_elementFuture.class,
continuation,
new String[]{endpoint_x,
'http://www.webserviceX.NET/GetCitiesByCountry',
'http://www.webserviceX.NET',
'GetCitiesByCountry',
'http://www.webserviceX.NET',
'GetCitiesByCountryResponse',
'WeatherRequestWebService2.GetCitiesByCountryResponse_element'}
);
}
public AsyncWeatherRequestWebService2.GetWeatherResponse_elementFuture beginGetWeather(System.Continuation continuation,String CityName,String CountryName) {
WeatherRequestWebService2.GetWeather_element request_x = new WeatherRequestWebService2.GetWeather_element();
request_x.CityName = CityName;
request_x.CountryName = CountryName;
return (AsyncWeatherRequestWebService2.GetWeatherResponse_elementFuture) System.WebServiceCallout.beginInvoke(
this,
request_x,
AsyncWeatherRequestWebService2.GetWeatherResponse_elementFuture.class,
continuation,
new String[]{endpoint_x,
'http://www.webserviceX.NET/GetWeather',
'http://www.webserviceX.NET',
'GetWeather',
'http://www.webserviceX.NET',
'GetWeatherResponse',
'WeatherRequestWebService2.GetWeatherResponse_element'}
);
}
}
}
I am just testing this using the execute anonymous window
AsyncWeatherRequestWebService2.GetWeatherResponse_elementFuture GetWeatherRequestService;
AsyncWeatherRequestWebService2.AsyncGlobalWeatherSoap GetWeatherRequest = new AsyncWeatherRequestWebService2.AsyncGlobalWeatherSoap();
Integer TIMEOUT_INT_SECS = 90;
Continuation cont = new Continuation(TIMEOUT_INT_SECS);
cont.continuationMethod = 'processResponse';
GetWeatherRequestService = GetWeatherRequest.beginGetWeather(cont, 'Paris','france');
GetWeatherRequestService.getValue();
and the error i am receiving is System.NullPointerException: Attempt to de-reference a null object pointing to return response.GetWeatherResult;
when i test the webservice using SOAPUI, it does return something.
so is this issue in the way i am calling the webservice? is the generated class missing something?
help please!
It is probably because of the
"cont.continuationMethod = 'processResponse'; "
does it require a call back method?
public Object processResponse() {
result = GetWeatherRequestService.getValue();
return result;
Best Answer
Wsdl2Apex now creates two sets of Apex classes for interacting with the SOAP based web service.
WebServiceCallout.invoke
and are synchronous. These are historically all that were generated.WebServiceCallout.beginInvoke
andWebServiceCallout.endInvoke
callsFor the purposes of testing the web service via anonymous apex you will want to use the former. It will have a name like
WeatherRequestWebService2
based on your sample code.E.g. (After adding Remote Sites setting for http://www.webservicex.net)
Gives: