How can I create a SOAP request with SOAP header and make an apex callout through WSDL2Apex class that I generated from WSDL. When I used WSDL2Apex and generated the class I just got one single apex class with the invoke method and other inner class which is part of the input parameter to the function which contains invoke method.

HttpRequest req = new HttpRequest();
 req.setEndpoint('my end point');
 // Specify the required user name and password to access the endpoint
 // As well as the header and header information
     String ordernumber='1-3234234';
 String content = 'ordernumber='+EncodingUtil.urlEncode(ordernumber, 'UTF-8');
 String username = 'username';
 String password = 'pass';

 Blob headerValue = Blob.valueOf(username + ':' + password);
 String authorizationHeader = 'BASIC ' +
 req.setHeader('Authorization', authorizationHeader);

 // Create a new http object to send the request object
 // A response object is generated as a result of the request  
 Http http = new Http();
 HTTPResponse res = http.send(req);

When I run the above code I get an exception:

<webM:message xml:lang="">Missing wsse:Security header in request</webM:message>

Am I not setting up the header properly here? What is the correct way to set the soap header. I have an username and password.

Another approach I followed is by adding header to the request like this:

stub.orderMMM sample = new stub.orderMMM();
stub.orderInput req = new stub.orderInput();
sample.endpoint_x = 'https://xyz/endpoint';
Map<String,String> m = new Map<String,String>();
sample.inputHttpHeaders_x = m;
stub.orderResponse res = sample.processOrder(req);
system.debug('******' + res);

But I get an error saying:

System.CalloutException: Web service callout failed: WebService returned a SOAP Fault: Missing wsse:Security header in request faultcode=wsse:InvalidSecurity faultactor=https://xyz.com
  • first you are making a Rest Request here not soap. Dec 15, 2016 at 4:57
  • How do I construct the SOAP request then ?
    – SfdcBat
    Dec 15, 2016 at 5:05
  • Check my answer. Dec 15, 2016 at 5:07
  • I would like to set a value for a parameter named order number. How can I set it in the request. Also I do not want to use oauth or session id at this moment . How can I set the username password I have in the soap header and send the request?
    – SfdcBat
    Dec 15, 2016 at 5:13
  • You can pass parameter in method paramter same as I passed Userid. You need to make a seperate call to get SessionId you will get that using user -password+Security Token. Dec 15, 2016 at 5:26

1 Answer 1


The response Missing wsse:Security header in request indicates the target service is expecting a WSSE Security header on the request. This isn't usually directly supported if you are using Wsdl2Apex as the WSSE elements are often missing from the WSDL.

You can however manually add the required SOAP header by creating some Apex classes for the Security and UsernameToken elements. These are then used with a _hns string to define the header. See Callouts from Salesforce – Adding Soap Headers for WSSE Security.

Your example code doesn't really look appropriate for invoking a SOAP based web service. For instance, a SOAP service would expect an XML body for the POST request.

Can you share the WSDL in question?

  • Please see my edit. Thanks for the response. I checked the link which you sent but I get a complier error at line where it says - public EkycId3API.Security Header; // Compile Error: Invalid type: EkycId3API.Security at line 255 column 16. Also please see my edit with a different approach I tried but was not successful. Any comments?
    – SfdcBat
    Dec 16, 2016 at 3:23
  • 1
    @SfdcBat You won't have the EkycId3API class name. You will need to change that to match your class name of gcsmsWebmethodsNaJnjComMu650Gcsms. inputHttpHeaders_x Won't work that is for HTTP headers rather than SOAP headers. Dec 16, 2016 at 6:25
  • I get this error now - System.CalloutException: Web service callout failed: WebService returned a SOAP Fault: The security token could not be authenticated or authorized faultcode=axis2ns24:FailedAuthentication faultactor=pfisnad.jnj.com/ws . Any idea what I might be doing wrong?
    – SfdcBat
    Dec 17, 2016 at 5:12
  • @SfdcBat Do you know what the authentication requirements are for the service you are calling? Can you make the required call with something more direct, like SOAP UI? Dec 18, 2016 at 7:04
  • Hi yes I can make a direct call from soup ui and get the response too. I need to include WSSE header in the request. I can send you the wsdl and Wsdl2apex and apex callout code to your email id. I am unable to share it here because of confidentiality. Please let me know if you are ok with that?
    – SfdcBat
    Dec 18, 2016 at 7:07

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .