+ Start a Discussion
jigglypufflyjigglypuffly 

Web service callout failed: Unable to find header type info forsecurityHeader

How to construct a security WSSE header in APEX code to make a SOAP call out?
This is the XML that I am trying to reproduce. 
<soapenv:Header>
      <wsse:Security soapenv:mustUnderstand="1" xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
         <wsse:UsernameToken xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
            <wsse:Username>USERNAME</wsse:Username>
            <wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText">PASSWORD</wsse:Password>
         </wsse:UsernameToken>
      </wsse:Security>
</soapenv:Header>

SOAP object class (WSDL2Apex):
... 
public class Soap {
        public SFMC_SOAP_TO_SF_SECURITY.SecurityHeader securityHeader = new SFMC_SOAP_TO_SF_SECURITY.SecurityHeader('USERNAME', 'PASSWORD');
        private String Security_hns = 'Security=http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd';
        public String endpoint_x = 'HIDDEN FOR PRIVACY';
        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://exacttarget.com/wsdl/partnerAPI', 'SFMC_SOAP_TO_SF_API'};
        public SFMC_SOAP_TO_SF_API.VersionInfoResponseMsg_element VersionInfo(Boolean IncludeVersionHistory) {
            SFMC_SOAP_TO_SF_API.VersionInfoRequestMsg_element request_x = new SFMC_SOAP_TO_SF_API.VersionInfoRequestMsg_element();
            request_x.IncludeVersionHistory = IncludeVersionHistory;
            SFMC_SOAP_TO_SF_API.VersionInfoResponseMsg_element response_x;
            Map<String, SFMC_SOAP_TO_SF_API.VersionInfoResponseMsg_element> response_map_x = new Map<String, SFMC_SOAP_TO_SF_API.VersionInfoResponseMsg_element>();
            response_map_x.put('response_x', response_x);
            WebServiceCallout.invoke(
              this,
              request_x,
              response_map_x,
              new String[]{endpoint_x,
              'VersionInfo',
              'http://exacttarget.com/wsdl/partnerAPI',
              'VersionInfoRequestMsg',
              'http://exacttarget.com/wsdl/partnerAPI',
              'VersionInfoResponseMsg',
              'SFMC_SOAP_TO_SF_API.VersionInfoResponseMsg_element'}
            );
            response_x = response_map_x.get('response_x');
            return response_x;
        }
public SFMC_SOAP_TO_SF_API.RetrieveResponseMsg_element Retrieve_x(SFMC_SOAP_TO_SF_API.RetrieveRequest RetrieveRequest) {
            SFMC_SOAP_TO_SF_API.RetrieveRequestMsg_element request_x = new SFMC_SOAP_TO_SF_API.RetrieveRequestMsg_element();
            request_x.RetrieveRequest = RetrieveRequest;
            SFMC_SOAP_TO_SF_API.RetrieveResponseMsg_element response_x;
            Map<String, SFMC_SOAP_TO_SF_API.RetrieveResponseMsg_element> response_map_x = new Map<String, SFMC_SOAP_TO_SF_API.RetrieveResponseMsg_element>();
            response_map_x.put('response_x', response_x);
            WebServiceCallout.invoke(
              this,
              request_x,
              response_map_x,
              new String[]{endpoint_x,
              'Retrieve',
              'http://exacttarget.com/wsdl/partnerAPI',
              'RetrieveRequestMsg',
              'http://exacttarget.com/wsdl/partnerAPI',
              'RetrieveResponseMsg',
              'SFMC_SOAP_TO_SF_API.RetrieveResponseMsg_element'}
            );
            response_x = response_map_x.get('response_x');
            return response_x;
}
...

Security Header class
public class SFMC_SOAP_TO_SF_SECURITY 
{

    public class UsernameToken {
        // Constructor for UsernameToken used to pass in username and password parameters
        public UsernameToken(String username, String password)
        {
            this.Username = username;
            this.Password = new password_e(password);
        }

        public String Username;
        public password_e Password;
        private String[] Username_type_info = new String[]{'Username','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[] apex_schema_type_info = new String[]{'http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd','true','false'};
        private String[] field_order_type_info = new String[]{'Username','Password'};

    }
    
        public class password_e{
            public password_e(String password) {
                this.password = password;
                type = 'http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText';             
    	}

            public String password;
            public string type; 
            public String[] type_att_info = new String[]{'Type'};        
            private String[] password_type_info = new String[]{'Password','http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText','string','1','1','false'};
            private String[] apex_schema_type_info = new String[]{'http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd','true','false'};
            private String[] field_order_type_info = new String[]{'password'};
    }

    
    
    // SecurityHeaderType Class
    public class SecurityHeaderType 
    {       
        // Constructor for SecurityHeaderType used to pass in username and password parameters and instantiate the UsernameToken object     
        public SecurityHeaderType(String username, String password)
        {
            this.UsernameToken = new SFMC_SOAP_TO_SF_SECURITY.UsernameToken(username, password);
        }

        public String wsuNamespace = 'http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd';              
        public SFMC_SOAP_TO_SF_SECURITY.UsernameToken UsernameToken;
        private String[] UsernameToken_type_info = new String[]{'UsernameToken','http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd','UsernameToken','1','1','false'};
        private String[] wsuNamespace_att_info = new String[]{'xmlns:wsu'};               
        private String[] apex_schema_type_info = new String[]{'http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd','true','false'};
        private String[] field_order_type_info = new String[]{'UsernameToken'};
    }
    

    public class SecurityHeader{
        
        public SecurityHeader(String username, String password){
            this.headerPackager = new SFMC_SOAP_TO_SF_SECURITY.SecurityHeaderType(username, password);
        }
    
        public String wsseNamespace = 'http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd';
        public SFMC_SOAP_TO_SF_SECURITY.SecurityHeaderType headerPackager;
		private String[] wsseNamespace_att_info = new String[]{'xmlns:wsse'};               
		private String[] apex_schema_type_info = new String[]{'http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd','true','false'};
		private String[] field_order_type_info = new String[]{'Security'}; 
        
    }
}