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
Anant Agarwal 15Anant Agarwal 15 

Issue in SOAP Header while making WebService Call

Hi All,

The WSDL I am generating through WSDL2Apex does not include the necessary SOAP Headers. Is there anyway to modify the generated apex code to include the SOAP Header properties? If so, how do I do that? I see the inputHttpHeaders__x but I am looking for the equivalent for SOAP Headers (if they exist)? 
If I am making a callout without header then I am getting the Error : "Wrong UserSessionID    : ORA-20103: no such user session id; ORA-06512: at -GCONF_NGE.CHECK_USER_SESSION_ID-" which is obvious as i am not authenticating first.

I need to set header in the given fromat: 

<soapenv:Header>
<wlm:Security xmlns:wlm= " http://schemas.xmlsoap.org/ws/2002/04/secext " >
<wlm:Authentication wlm:login= " test” wlm:password= " test”/>
</wlm:Security>
</soapenv:Header>

Don't know how to set this header in the SOAP Request. 

Here is my generated code that i need to call:
public String WSExpCreateHousehold(String param0) {
            wsMmFr.WSExpCreateHousehold_element request_x = new wsMmFr.WSExpCreateHousehold_element();
            request_x.param0 = param0;
            wsMmFr.WSExpCreateHouseholdResponse_element response_x;
            Map<String, wsMmFr.WSExpCreateHouseholdResponse_element> response_map_x = new Map<String, wsMmFr.WSExpCreateHouseholdResponse_element>();
            response_map_x.put('response_x', response_x);
            WebServiceCallout.invoke(
              this,
              request_x,
              response_map_x,
              new String[]{endpoint_x,
              'urn:WSExpCreateHousehold',
              'http://ws.mm.fr',
              'WSExpCreateHousehold',
              'http://ws.mm.fr',
              'WSExpCreateHouseholdResponse',
              'wsMmFr.WSExpCreateHouseholdResponse_element'}
            );
            response_x = response_map_x.get('response_x');
            return response_x.return_x;
        }

 
Daniel BallingerDaniel Ballinger
There is a blog post Callouts from Salesforce – Adding Soap Headers for WSSE Security (http://blog.dacology.com/callouts-from-salesforce-adding-soap-headers-for-wsse-security/). It is about setting a BinarySecurityToken header. It differs ever so slightly, have has the core information about using the _hns suffix for setting SOAP headers via WebServiceCallout.invoke.
 
Anant Agarwal 15Anant Agarwal 15
Hi Daniel, Thanks for your response. That blog is very helping. But still i am facing some issue:
  • In my header, login and password is set as an attribute and not as a tag. Can you please help me out how to convert the above header xml into apex class having login and password as an attribute instead of tag.
  • Also, is there any way that i can debug my request envelope. So that i can be sure that i am sending the correct request to the Web Service.