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
paul-lmipaul-lmi 

WebServiceCallout.invoke not writing HTTP headers

I generated an Apex class via WSDL2Apex, and I'm trying to debug an issue with maintaining session headers.  Regarding the section that talks about outputting headers here http://wiki.developerforce.com/index.php/Apex_Web_Services_and_Callouts

 

the  outputHttpHeaders_x Map is null, and it doesn't appear to do anything beside being created in the class.  How can I tewak the callout to actually write the header information to this Map so I can access and reuse the session header?

 

Here's the generated code snippet I'm trying to debug:

 

//Generated by wsdl2apex public class InstranetSession { public class logout_element { private String[] apex_schema_type_info = new String[]{'http://services.instranet.com','true','true'}; private String[] field_order_type_info = new String[]{}; } public class loginResponse_element { private String[] apex_schema_type_info = new String[]{'http://services.instranet.com','true','true'}; private String[] field_order_type_info = new String[]{}; } public class SessionServiceHttpPort { public String endpoint_x = 'https://hidden/kblive/ccil/services/SessionService'; public Map<String,String> inputHttpHeaders_x; public Map<String,String> outputHttpHeaders_x; public String clientCert_x; public String clientCertPasswd_x; public Integer timeout_x; private String[] ns_map_type_info = new String[]{'http://services.instranet.com', 'InstranetSession'}; public void login(String userLogin,String password) { InstranetSession.login_element request_x = new InstranetSession.login_element(); InstranetSession.loginResponse_element response_x; request_x.userLogin = userLogin; request_x.password = password; Map<String, InstranetSession.loginResponse_element> response_map_x = new Map<String, InstranetSession.loginResponse_element>(); response_map_x.put('response_x', response_x); WebServiceCallout.invoke( this, request_x, response_map_x, new String[]{endpoint_x, '', 'http://services.instranet.com', 'login', 'http://services.instranet.com', 'loginResponse', 'InstranetSession.loginResponse_element'} ); response_x = response_map_x.get('response_x'); } public void acceptLanguage(String languages) { InstranetSession.acceptLanguage_element request_x = new InstranetSession.acceptLanguage_element(); InstranetSession.acceptLanguageResponse_element response_x; request_x.languages = languages; Map<String, InstranetSession.acceptLanguageResponse_element> response_map_x = new Map<String, InstranetSession.acceptLanguageResponse_element>(); response_map_x.put('response_x', response_x); WebServiceCallout.invoke( this, request_x, response_map_x, new String[]{endpoint_x, '', 'http://services.instranet.com', 'acceptLanguage', 'http://services.instranet.com', 'acceptLanguageResponse', 'InstranetSession.acceptLanguageResponse_element'} ); response_x = response_map_x.get('response_x'); } public void logout() { InstranetSession.logout_element request_x = new InstranetSession.logout_element(); InstranetSession.logoutResponse_element response_x; Map<String, InstranetSession.logoutResponse_element> response_map_x = new Map<String, InstranetSession.logoutResponse_element>(); response_map_x.put('response_x', response_x); WebServiceCallout.invoke( this, request_x, response_map_x, new String[]{endpoint_x, '', 'http://services.instranet.com', 'logout', 'http://services.instranet.com', 'logoutResponse', 'InstranetSession.logoutResponse_element'} ); response_x = response_map_x.get('response_x'); } } public class acceptLanguageResponse_element { private String[] apex_schema_type_info = new String[]{'http://services.instranet.com','true','true'}; private String[] field_order_type_info = new String[]{}; } public class ServiceError { public String errorType; public String message; private String[] errorType_type_info = new String[]{'errorType','http://services.instranet.com','ServiceErrorType','0','1','true'}; private String[] message_type_info = new String[]{'message','http://www.w3.org/2001/XMLSchema','string','0','1','true'}; private String[] apex_schema_type_info = new String[]{'http://services.instranet.com','true','true'}; private String[] field_order_type_info = new String[]{'errorType','message'}; } public class login_element { public String userLogin; public String password; private String[] userLogin_type_info = new String[]{'userLogin','http://www.w3.org/2001/XMLSchema','string','1','1','true'}; private String[] password_type_info = new String[]{'password','http://www.w3.org/2001/XMLSchema','string','1','1','true'}; private String[] apex_schema_type_info = new String[]{'http://services.instranet.com','true','true'}; private String[] field_order_type_info = new String[]{'userLogin','password'}; } public class acceptLanguage_element { public String languages; private String[] languages_type_info = new String[]{'languages','http://www.w3.org/2001/XMLSchema','string','1','1','true'}; private String[] apex_schema_type_info = new String[]{'http://services.instranet.com','true','true'}; private String[] field_order_type_info = new String[]{'languages'}; } public class logoutResponse_element { private String[] apex_schema_type_info = new String[]{'http://services.instranet.com','true','true'}; private String[] field_order_type_info = new String[]{}; } }

 

 

 Can anyone tell me why the response headers aren't being written to the map and/or how to resolve this hole in teh WSDL2Apex generated code?  And, also, where oh where is the documentation on the WebServiceCallout Apex class? 

 

 

cheenathcheenath

You need to assign a new instance of the map, eg:

 

InstranetSession.SessionServiceHttpPort stub = new ...

 

stub.inputHttpHeaders_x = new HashMap<String, String>();

stub.outputHttpHeaders_x =  new HashMap...

 

 

//to send http header:

stub.inputHttpHeaders_x.put('header-to-send', 'value');

 

 

//to read the response header

String session = stub.outputHttpHeaders_x.get('SESSION');

 

 

HTHs,

 

 

 

 

paul-lmipaul-lmi

got it going.

 

InstranetSession.SessionServiceHttpPort ses = new InstranetSession.SessionServiceHttpPort();
ses.outputHttpHeaders_x = new Map<string, string>();
ses.login('ssd-guest','ssd-guest');
system.debug('headers: ' + ses.outputHttpHeaders_x);

Manoj_Manoj_

This might be a old discussion. But I am facing the same problem. Can you please help me out.

 

This is the link to the origina post I created. Can you please help me?

 

http://community.salesforce.com/t5/Apex-Code-Development/Issue-with-reading-response-http-headers-from-soap-webservice/td-p/185397

 

Thanks,

Manoj