+ Start a Discussion
Manoj_Manoj_ 

Issue with reading response http headers from soap webservice callout

I have an issue reading the headers from the soap response and here are the steps I did

1. Create the class using wsdl2apex

2. Made a webservice callout to the logon method and the method was successful and it returned a logon success message

3. The webservice callout also returns the sessionid in the response headers. I am not able to read the response headers from the callout.

4. Salesforce debug log shows the webservice callout profiling information. I can see the following line that contains the headers

9:53:31.492|CALLOUT_RESPONSE|[66,13]|<?xml version="1.0" encoding="utf-8"?><soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><soap:Header><Header xmlns="http://www.twinfield.com/"><SessionID>6ad74r65-2333c-43tf1-9501-adf31d5r4da2</SessionID></Header></soap:Header><soap:Body><LogonResponse xmlns="http://www.twinfield.com/"><LogonResult>Ok</LogonResult><nextAction>None</nextAction><cluster>https://c1.twinfield.com</cluster></LogonResponse></soap:Body></soap:Envelope>
5. Can you please help me on how to read the response headers in this case? I tried every possibility in vain.

================================================================================================

//Generated by wsdl2apex

public class WSDLClassTwinfieldSession {
    public static WSDLClassTwinfieldSession.LogonResponse_element login(String user_x,String password,String organisation){
        WSDLClassTwinfieldSession.LogonResponse_element logonResponse = null;
        WSDLClassTwinfieldSession.SessionSoap soap = new WSDLClassTwinfieldSession.SessionSoap();
        soap.outputHttpHeaders_x = new Map<string, string>();
        logonResponse = soap.Logon(user_x, password, organisation);
        System.debug('Logon Response ='+logonResponse);
        System.debug('headers: ' + soap.outputHttpHeaders_x);
        return logonResponse;
    }
    public class SessionSoap {
        public String endpoint_x = 'https://login.twinfield.com/webservices/session.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;
        public WSDLClassTwinfieldSession.Header Header;
        private String Header_hns = 'Header=http://www.twinfield.com/';
        private String[] ns_map_type_info = new String[]{'http://www.twinfield.com/', 'WSDLClassTwinfieldSession'};
        public void Abandon() {
            WSDLClassTwinfieldSession.Abandon_element request_x = new WSDLClassTwinfieldSession.Abandon_element();
            WSDLClassTwinfieldSession.AbandonResponse_element response_x;
            Map<String, WSDLClassTwinfieldSession.AbandonResponse_element> response_map_x = new Map<String, WSDLClassTwinfieldSession.AbandonResponse_element>();
            response_map_x.put('response_x', response_x);
            WebServiceCallout.invoke(
              this,
              request_x,
              response_map_x,
              new String[]{endpoint_x,
              'http://www.twinfield.com/Abandon',
              'http://www.twinfield.com/',
              'Abandon',
              'http://www.twinfield.com/',
              'AbandonResponse',
              'WSDLClassTwinfieldSession.AbandonResponse_element'}
            );
            response_x = response_map_x.get('response_x');
        }
        public WSDLClassTwinfieldSession.LogonResponse_element Logon(String user_x,String password,String organisation) {
            WSDLClassTwinfieldSession.Logon_element request_x = new WSDLClassTwinfieldSession.Logon_element();
            WSDLClassTwinfieldSession.LogonResponse_element response_x;
            request_x.user_x = user_x;
            request_x.password = password;
            request_x.organisation = organisation;
            Map<String, WSDLClassTwinfieldSession.LogonResponse_element> response_map_x = new Map<String, WSDLClassTwinfieldSession.LogonResponse_element>();
            response_map_x.put('response_x', response_x);
            WebServiceCallout.invoke(
              this,
              request_x,
              response_map_x,
              new String[]{endpoint_x,
              'http://www.twinfield.com/Logon',
              'http://www.twinfield.com/',
              'Logon',
              'http://www.twinfield.com/',
              'LogonResponse',
              'WSDLClassTwinfieldSession.LogonResponse_element'}
            );
            response_x = response_map_x.get('response_x');
            return response_x;
        }
    }
    public class LogonResponse_element {
        public String LogonResult;
        public String nextAction;
        public String cluster;
        private String[] LogonResult_type_info = new String[]{'LogonResult','http://www.twinfield.com/','LogonResult','1','1','false'};
        private String[] nextAction_type_info = new String[]{'nextAction','http://www.twinfield.com/','LogonAction','1','1','false'};
        private String[] cluster_type_info = new String[]{'cluster','http://www.w3.org/2001/XMLSchema','string','0','1','false'};
        private String[] apex_schema_type_info = new String[]{'http://www.twinfield.com/','true','false'};
        private String[] field_order_type_info = new String[]{'LogonResult','nextAction','cluster'};
    }
    public class Header {
        public String SessionID;
        private String[] SessionID_type_info = new String[]{'SessionID','http://www.w3.org/2001/XMLSchema','string','0','1','false'};
        private String[] apex_schema_type_info = new String[]{'http://www.twinfield.com/','true','false'};
        private String[] field_order_type_info = new String[]{'SessionID'};
    }
    public class Logon_element {
        public String user_x;
        public String password;
        public String organisation;
        private String[] user_x_type_info = new String[]{'user','http://www.w3.org/2001/XMLSchema','string','0','1','false'};
        private String[] password_type_info = new String[]{'password','http://www.w3.org/2001/XMLSchema','string','0','1','false'};
        private String[] organisation_type_info = new String[]{'organisation','http://www.w3.org/2001/XMLSchema','string','0','1','false'};
        private String[] apex_schema_type_info = new String[]{'http://www.twinfield.com/','true','false'};
        private String[] field_order_type_info = new String[]{'user_x','password','organisation'};
    }
}

==========================================================================================

I am calling the above class in the following way

WSDLClassTwinfieldSession.login('username','password','org');

@altius_rup@altius_rup
Hi Manoj_,
I have the same problem as you : did you find an answer to your question ?

Rup