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

How to set a SOAP Header using WSDL2Java

I know there are some Java/Axis gurus in salesforce, so I'm hoping one might answer the following:  how does one add a SOAP Header when using code generated by WSDL2Java?


Here are the details:

I'm trying to consume an authentication web service.  The WSDL specifies that the username and password are passed in the SOAP header.  Here is the relevant section of the WSDL:

<operation name="Logon">
      <soap:operation soapAction="http://MerrillLynch.Framework.Security/Logon" style="document" />
        <soap:body use="literal" />
        <soap:header d5p1:required="true" message="s0:LogonAuthHeader" part="AuthHeader" use="literal" xmlns:d5p1="" />
        <soap:body use="literal" />


But in the Java code generated by WSDL2Java, I'm not seeing how add this SOAP header using the methods provided.    I've done the usual Googling, but there is nothing that I can that tells how to do it in a straightforward manner.


Does anyone know the trick?






Problem solved:

AuthHeader ah = new AuthHeader();

        WsSecLogonSoapStub w = (WsSecLogonSoapStub) new WsSecLogonLocator().getwsSecLogonSoap(u);

        w.setHeader(new WsSecLogonLocator().getServiceName().getNamespaceURI(),"AuthHeader", ah);