function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion

how to call webservices from vfpage

Hi iam having two fields (serial number,product number) and a button submit in a vfpage, when give the sno,pno and click on the submit it has to call the external webservice and get response as productnumber,productdescription in a table or grid ,the out put has to be shown on the same vfpage..
  iam having a wsdl from that i generated the apexclasses then how to get the response from externalwebservices
Pat PattersonPat Patterson
Typically, you will define an Apex action function for your Visualforce page that does the callout. Here's a good article with the basics of Apex Web Services: Apex Web Services and Callouts (

Here's an example of calling a web service to get postage rates:

    public PageReference makePostageLabel() {
        EnvmgrLabelService.LabelRequest labelRequest = new EnvmgrLabelService.LabelRequest();
        labelRequest.RequesterID = 'abcd';
        labelRequest.AccountID = '123456';

        labelRequest.MailClass = mailClass; // Controller properties - bound to fields in VF page
        labelRequest.MailpieceShape = mailpieceShape;
        // etc

        // Get the SOAP service
        EnvmgrLabelService.EwsLabelServiceSoap service = new EnvmgrLabelService.EwsLabelServiceSoap();

        // Call the web service
        EnvmgrLabelService.LabelRequestResponse labelResponse = service.GetPostageLabel(labelRequest);

        // See what happened - status, postageLabel, finalPostage can also be bound to fields in a VF page
        if ( labelResponse.Status == 0 ) {
            status = 'Label created';
            postageLabel = labelResponse.Base64LabelImage;           
        } else {
            status = labelResponse.ErrorMessage;
            postageLabel = blank;
        List<String> format = new String[]{'0','number','###,###,##0.00'};
        finalPostage = String.format(labelResponse.FinalPostage.format(), format);

        // Return null to stay on the same page and show the result. Could also send the status etc to
        // another page - set parameters on the PageReference
        return null;