1

I need to make an external SOAP web service callout to get weather forecast by sending zip code and also need to populate graphically in UI. I am new to web services. Hence please give a detailed info. I have generated apex class using WSDL.

//Generated by wsdl2apex

            public class WeatherReportFromCdyne {
                public class temp {
                    public String MorningLow;
                    public String DaytimeHigh;
                    private String[] MorningLow_type_info = new String[]{'MorningLow','http://ws.cdyne.com/WeatherWS/',null,'0','1','false'};
                    private String[] DaytimeHigh_type_info = new String[]{'DaytimeHigh','http://ws.cdyne.com/WeatherWS/',null,'0','1','false'};
                    private String[] apex_schema_type_info = new String[]{'http://ws.cdyne.com/WeatherWS/','true','false'};
                    private String[] field_order_type_info = new String[]{'MorningLow','DaytimeHigh'};
                }
                public class GetWeatherInformation_element {
                    private String[] apex_schema_type_info = new String[]{'http://ws.cdyne.com/WeatherWS/','true','false'};
                    private String[] field_order_type_info = new String[]{};
                }
                public class ForecastReturn {
                    public Boolean Success;
                    public String ResponseText;
                    public String State;
                    public String City;
                    public String WeatherStationCity;
                    public WeatherReportFromCdyne.ArrayOfForecast ForecastResult;
                    private String[] Success_type_info = new String[]{'Success','http://ws.cdyne.com/WeatherWS/',null,'1','1','false'};
                    private String[] ResponseText_type_info = new String[]{'ResponseText','http://ws.cdyne.com/WeatherWS/',null,'0','1','false'};
                    private String[] State_type_info = new String[]{'State','http://ws.cdyne.com/WeatherWS/',null,'0','1','false'};
                    private String[] City_type_info = new String[]{'City','http://ws.cdyne.com/WeatherWS/',null,'0','1','false'};
                    private String[] WeatherStationCity_type_info = new String[]{'WeatherStationCity','http://ws.cdyne.com/WeatherWS/',null,'0','1','false'};
                    private String[] ForecastResult_type_info = new String[]{'ForecastResult','http://ws.cdyne.com/WeatherWS/',null,'0','1','false'};
                    private String[] apex_schema_type_info = new String[]{'http://ws.cdyne.com/WeatherWS/','true','false'};
                    private String[] field_order_type_info = new String[]{'Success','ResponseText','State','City','WeatherStationCity','ForecastResult'};
                }
                public class WeatherDescription {
                    public Integer WeatherID;
                    public String Description;
                    public String PictureURL;
                    private String[] WeatherID_type_info = new String[]{'WeatherID','http://ws.cdyne.com/WeatherWS/',null,'1','1','false'};
                    private String[] Description_type_info = new String[]{'Description','http://ws.cdyne.com/WeatherWS/',null,'0','1','false'};
                    private String[] PictureURL_type_info = new String[]{'PictureURL','http://ws.cdyne.com/WeatherWS/',null,'0','1','false'};
                    private String[] apex_schema_type_info = new String[]{'http://ws.cdyne.com/WeatherWS/','true','false'};
                    private String[] field_order_type_info = new String[]{'WeatherID','Description','PictureURL'};
                }
                public class GetCityForecastByZIP_element {
                    public String ZIP;
                    private String[] ZIP_type_info = new String[]{'ZIP','http://ws.cdyne.com/WeatherWS/',null,'0','1','false'};
                    private String[] apex_schema_type_info = new String[]{'http://ws.cdyne.com/WeatherWS/','true','false'};
                    private String[] field_order_type_info = new String[]{'ZIP'};
                }
                public class GetCityWeatherByZIP_element {
                    public String ZIP;
                    private String[] ZIP_type_info = new String[]{'ZIP','http://ws.cdyne.com/WeatherWS/',null,'0','1','false'};
                    private String[] apex_schema_type_info = new String[]{'http://ws.cdyne.com/WeatherWS/','true','false'};
                    private String[] field_order_type_info = new String[]{'ZIP'};
                }
                public class WeatherReturn {
                    public Boolean Success {get;set;}
                    public String ResponseText {get;set;}
                    public String State {get;set;}
                    public String City {get;set;}
                    public String WeatherStationCity {get;set;}
                    public Integer WeatherID {get;set;}
                    public String Description {get;set;}
                    public String Temperature {get;set;}
                    public String RelativeHumidity {get;set;}
                    public String Wind {get;set;}
                    public String Pressure {get;set;}
                    public String Visibility {get;set;}
                    public String WindChill {get;set;}
                    public String Remarks {get;set;}
                    private String[] Success_type_info = new String[]{'Success','http://ws.cdyne.com/WeatherWS/',null,'1','1','false'};
                    private String[] ResponseText_type_info = new String[]{'ResponseText','http://ws.cdyne.com/WeatherWS/',null,'0','1','false'};
                    private String[] State_type_info = new String[]{'State','http://ws.cdyne.com/WeatherWS/',null,'0','1','false'};
                    private String[] City_type_info = new String[]{'City','http://ws.cdyne.com/WeatherWS/',null,'0','1','false'};
                    private String[] WeatherStationCity_type_info = new String[]{'WeatherStationCity','http://ws.cdyne.com/WeatherWS/',null,'0','1','false'};
                    private String[] WeatherID_type_info = new String[]{'WeatherID','http://ws.cdyne.com/WeatherWS/',null,'1','1','false'};
                    private String[] Description_type_info = new String[]{'Description','http://ws.cdyne.com/WeatherWS/',null,'0','1','false'};
                    private String[] Temperature_type_info = new String[]{'Temperature','http://ws.cdyne.com/WeatherWS/',null,'0','1','false'};
                    private String[] RelativeHumidity_type_info = new String[]{'RelativeHumidity','http://ws.cdyne.com/WeatherWS/',null,'0','1','false'};
                    private String[] Wind_type_info = new String[]{'Wind','http://ws.cdyne.com/WeatherWS/',null,'0','1','false'};
                    private String[] Pressure_type_info = new String[]{'Pressure','http://ws.cdyne.com/WeatherWS/',null,'0','1','false'};
                    private String[] Visibility_type_info = new String[]{'Visibility','http://ws.cdyne.com/WeatherWS/',null,'0','1','false'};
                    private String[] WindChill_type_info = new String[]{'WindChill','http://ws.cdyne.com/WeatherWS/',null,'0','1','false'};
                    private String[] Remarks_type_info = new String[]{'Remarks','http://ws.cdyne.com/WeatherWS/',null,'0','1','false'};
                    private String[] apex_schema_type_info = new String[]{'http://ws.cdyne.com/WeatherWS/','true','false'};
                    private String[] field_order_type_info = new String[]{'Success','ResponseText','State','City','WeatherStationCity','WeatherID','Description','Temperature','RelativeHumidity','Wind','Pressure','Visibility','WindChill','Remarks'};
                }
                public class POP {
                    public String Nighttime;
                    public String Daytime;
                    private String[] Nighttime_type_info = new String[]{'Nighttime','http://ws.cdyne.com/WeatherWS/',null,'0','1','false'};
                    private String[] Daytime_type_info = new String[]{'Daytime','http://ws.cdyne.com/WeatherWS/',null,'0','1','false'};
                    private String[] apex_schema_type_info = new String[]{'http://ws.cdyne.com/WeatherWS/','true','false'};
                    private String[] field_order_type_info = new String[]{'Nighttime','Daytime'};
                }
                public class GetCityForecastByZIPResponse_element {
                    public WeatherReportFromCdyne.ForecastReturn GetCityForecastByZIPResult;
                    private String[] GetCityForecastByZIPResult_type_info = new String[]{'GetCityForecastByZIPResult','http://ws.cdyne.com/WeatherWS/',null,'0','1','false'};
                    private String[] apex_schema_type_info = new String[]{'http://ws.cdyne.com/WeatherWS/','true','false'};
                    private String[] field_order_type_info = new String[]{'GetCityForecastByZIPResult'};
                }
                public class GetCityWeatherByZIPResponse_element {
                    public WeatherReportFromCdyne.WeatherReturn GetCityWeatherByZIPResult;
                    private String[] GetCityWeatherByZIPResult_type_info = new String[]{'GetCityWeatherByZIPResult','http://ws.cdyne.com/WeatherWS/',null,'1','1','false'};
                    private String[] apex_schema_type_info = new String[]{'http://ws.cdyne.com/WeatherWS/','true','false'};
                    private String[] field_order_type_info = new String[]{'GetCityWeatherByZIPResult'};
                }
                public class Forecast {
                    public DateTime Date_x;
                    public Integer WeatherID;
                    public String Desciption;
                    public WeatherReportFromCdyne.temp Temperatures;
                    public WeatherReportFromCdyne.POP ProbabilityOfPrecipiation;
                    private String[] Date_x_type_info = new String[]{'Date','http://ws.cdyne.com/WeatherWS/',null,'1','1','false'};
                    private String[] WeatherID_type_info = new String[]{'WeatherID','http://ws.cdyne.com/WeatherWS/',null,'1','1','false'};
                    private String[] Desciption_type_info = new String[]{'Desciption','http://ws.cdyne.com/WeatherWS/',null,'0','1','false'};
                    private String[] Temperatures_type_info = new String[]{'Temperatures','http://ws.cdyne.com/WeatherWS/',null,'1','1','false'};
                    private String[] ProbabilityOfPrecipiation_type_info = new String[]{'ProbabilityOfPrecipiation','http://ws.cdyne.com/WeatherWS/',null,'1','1','false'};
                    private String[] apex_schema_type_info = new String[]{'http://ws.cdyne.com/WeatherWS/','true','false'};
                    private String[] field_order_type_info = new String[]{'Date_x','WeatherID','Desciption','Temperatures','ProbabilityOfPrecipiation'};
                }
                public class GetWeatherInformationResponse_element {
                    public WeatherReportFromCdyne.ArrayOfWeatherDescription GetWeatherInformationResult;
                    private String[] GetWeatherInformationResult_type_info = new String[]{'GetWeatherInformationResult','http://ws.cdyne.com/WeatherWS/',null,'0','1','false'};
                    private String[] apex_schema_type_info = new String[]{'http://ws.cdyne.com/WeatherWS/','true','false'};
                    private String[] field_order_type_info = new String[]{'GetWeatherInformationResult'};
                }
                public class ArrayOfForecast {
                    public WeatherReportFromCdyne.Forecast[] Forecast;
                    private String[] Forecast_type_info = new String[]{'Forecast','http://ws.cdyne.com/WeatherWS/',null,'0','-1','true'};
                    private String[] apex_schema_type_info = new String[]{'http://ws.cdyne.com/WeatherWS/','true','false'};
                    private String[] field_order_type_info = new String[]{'Forecast'};
                }
                public class ArrayOfWeatherDescription {
                    public WeatherReportFromCdyne.WeatherDescription[] WeatherDescription;
                    private String[] WeatherDescription_type_info = new String[]{'WeatherDescription','http://ws.cdyne.com/WeatherWS/',null,'0','-1','false'};
                    private String[] apex_schema_type_info = new String[]{'http://ws.cdyne.com/WeatherWS/','true','false'};
                    private String[] field_order_type_info = new String[]{'WeatherDescription'};
                }
                public class WeatherSoap {
                    public String endpoint_x = 'http://wsf.cdyne.com/WeatherWS/Weather.asmx';
                    public Map<String,String> inputHttpHeaders_x;
                    public Map<String,String> outputHttpHeaders_x;
                    public String clientCertName_x;
                    public String clientCert_x;
                    public String clientCertPasswd_x;
                    public Integer timeout_x;
                    private String[] ns_map_type_info = new String[]{'http://ws.cdyne.com/WeatherWS/', 'WeatherReportFromCdyne'};
                    public WeatherReportFromCdyne.ArrayOfWeatherDescription GetWeatherInformation() {
                        WeatherReportFromCdyne.GetWeatherInformation_element request_x = new WeatherReportFromCdyne.GetWeatherInformation_element();
                        WeatherReportFromCdyne.GetWeatherInformationResponse_element response_x;
                        Map<String, WeatherReportFromCdyne.GetWeatherInformationResponse_element> response_map_x = new Map<String, WeatherReportFromCdyne.GetWeatherInformationResponse_element>();
                        response_map_x.put('response_x', response_x);
                        WebServiceCallout.invoke(
                          this,
                          request_x,
                          response_map_x,
                          new String[]{endpoint_x,
                          'http://ws.cdyne.com/WeatherWS/GetWeatherInformation',
                          'http://ws.cdyne.com/WeatherWS/',
                          'GetWeatherInformation',
                          'http://ws.cdyne.com/WeatherWS/',
                          'GetWeatherInformationResponse',
                          'WeatherReportFromCdyne.GetWeatherInformationResponse_element'}
                        );
                        response_x = response_map_x.get('response_x');
                        return response_x.GetWeatherInformationResult;
                    }
                    public WeatherReportFromCdyne.WeatherReturn GetCityWeatherByZIP(String ZIP) {
                        WeatherReportFromCdyne.GetCityWeatherByZIP_element request_x = new WeatherReportFromCdyne.GetCityWeatherByZIP_element();
                        request_x.ZIP = ZIP;
                        WeatherReportFromCdyne.GetCityWeatherByZIPResponse_element response_x;
                        Map<String, WeatherReportFromCdyne.GetCityWeatherByZIPResponse_element> response_map_x = new Map<String, WeatherReportFromCdyne.GetCityWeatherByZIPResponse_element>();
                        response_map_x.put('response_x', response_x);
                        WebServiceCallout.invoke(
                          this,
                          request_x,
                          response_map_x,
                          new String[]{endpoint_x,
                          'http://ws.cdyne.com/WeatherWS/GetCityWeatherByZIP',
                          'http://ws.cdyne.com/WeatherWS/',
                          'GetCityWeatherByZIP',
                          'http://ws.cdyne.com/WeatherWS/',
                          'GetCityWeatherByZIPResponse',
                          'WeatherReportFromCdyne.GetCityWeatherByZIPResponse_element'}
                        );
                        response_x = response_map_x.get('response_x');
                        return response_x.GetCityWeatherByZIPResult;
                    }
                    public WeatherReportFromCdyne.ForecastReturn GetCityForecastByZIP(String ZIP) {
                        WeatherReportFromCdyne.GetCityForecastByZIP_element request_x = new WeatherReportFromCdyne.GetCityForecastByZIP_element();
                        request_x.ZIP = ZIP;
                        WeatherReportFromCdyne.GetCityForecastByZIPResponse_element response_x;
                        Map<String, WeatherReportFromCdyne.GetCityForecastByZIPResponse_element> response_map_x = new Map<String, WeatherReportFromCdyne.GetCityForecastByZIPResponse_element>();
                        response_map_x.put('response_x', response_x);
                        WebServiceCallout.invoke(
                          this,
                          request_x,
                          response_map_x,
                          new String[]{endpoint_x,
                          'http://ws.cdyne.com/WeatherWS/GetCityForecastByZIP',
                          'http://ws.cdyne.com/WeatherWS/',
                          'GetCityForecastByZIP',
                          'http://ws.cdyne.com/WeatherWS/',
                          'GetCityForecastByZIPResponse',
                          'WeatherReportFromCdyne.GetCityForecastByZIPResponse_element'}
                        );
                        response_x = response_map_x.get('response_x');
                        return response_x.GetCityForecastByZIPResult;
                    }
                }
            }
4
  • Whats the error you are getting ?Can you elaborate what you need ? – Mohith Shrivastava Mar 21 '16 at 18:54
  • @Ean what error you are getting now? – Ratan Paul Mar 22 '16 at 5:26
  • @sfdcweb I forgot to specify access modifier for the model value. Now the issue is resolved. However I need to show a graphical representation using the data i got from web service instead of just binding in table. Any ideas? – Ean Mar 22 '16 at 5:29
  • @Ean I suggest first try with your self. If you stuck somewhere while designing.. ask in community and if you provide more info like image etc to view how you want to display then so many members will help you. And ask a new question . Thanks – Ratan Paul Mar 22 '16 at 5:32
1

You can store the result in a apex property and create getters and setters for apex properties you want to display

To help you with an example here is a sample code to get you started

public class resultDisplayCtrl{
   public WeatherInformation.WeatherForecasts results {get;set;}

   public pagereference getData(){
     WeatherReportFromCdyne.WeatherSoap  obj = new WeatherReportFromCdyne.WeatherSoap (); 
     WeatherInformation.WeatherForecasts results = obj.GetCityWeatherByZIP('95007');
      return null;
   }

}

Note : Mark properties on your Weather Information class as getters and setters so you can display on the VF

example

public class WeatherForecasts {
                public Double Latitude {get;set;}
                public Double Longitude {get;set;}
                public Double AllocationFactor {get;set;}
                public String FipsCode {get;set;}
                public String PlaceName {get;set;}
                public String StateCode {get;set;}
                public String Status {get;set;}
                public WeatherInformation.ArrayOfWeatherData Details;
                private String[] Latitude_type_info = new String[]{'Latitude','http://www.webservicex.net',null,'1','1','false'};
                private String[] Longitude_type_info = new String[]{'Longitude','http://www.webservicex.net',null,'1','1','false'};
                private String[] AllocationFactor_type_info = new String[]{'AllocationFactor','http://www.webservicex.net',null,'1','1','false'};
                private String[] FipsCode_type_info = new String[]{'FipsCode','http://www.webservicex.net',null,'0','1','false'};
                private String[] PlaceName_type_info = new String[]{'PlaceName','http://www.webservicex.net',null,'0','1','false'};
                private String[] StateCode_type_info = new String[]{'StateCode','http://www.webservicex.net',null,'0','1','false'};
                private String[] Status_type_info = new String[]{'Status','http://www.webservicex.net',null,'0','1','false'};
                private String[] Details_type_info = new String[]{'Details','http://www.webservicex.net',null,'0','1','false'};
                private String[] apex_schema_type_info = new String[]{'http://www.webservicex.net','true','false'};
                private String[] field_order_type_info = new String[]{'Latitude','Longitude','AllocationFactor','FipsCode','PlaceName','StateCode','Status','Details'};
            }

Visualforce code

<apex:page controller="resultDisplayCtrl"> 
  <apex:commandbutton value="callWebservice" action="{!getData}"/>
  //write your vf markup to show each property from result set
  <!--Sample Tag-->
  <apex:outputtext value="{!result.Latitude}" />
  <apex:outputtext value="{!result.AllocationFactor}" />
</apex:page>
7
  • Thanks for the info. I will try it and get back if i face any hurdles. Can i be able to show a graphical representation of weather with the details that i receive like we do with google maps plotting markers. If yes please tell me how to do that. – Ean Mar 21 '16 at 19:22
  • Yes all those are possible .Please show note people here are helpful provided you show your effort .Look through docs ,google before posting a question .Thanks – Mohith Shrivastava Mar 21 '16 at 19:23
  • I tried searching but couldn't find any example how to do that. That's why i asked for help. – Ean Mar 21 '16 at 19:27
  • I have tried your way but seems to get struck in the middle. I have updated the question. Please provide your feedback. – Ean Mar 21 '16 at 20:10
  • You dont need page block table there .The object is not array .So please use outputtexts and html table – Mohith Shrivastava Mar 21 '16 at 20:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.