Title: RE: Adding SOAP header in Axis client

    I am trying to transmit a SOAP header from my Axis client, but it is not working. Below is the manually modified stub code that tries to add the header to the SOAP message:

        Document doc = XMLUtils.newDocument();
        Element root = doc.createElementNS(HEADER_NAMESPACE, HEADER_LOCAL_NAME);
        Element subElem = doc.createElementNS(HEADER_NAMESPACE, LOCAL_NAME);
        Text text = doc.createTextNode("hello");
        subElem.appendChild(text);
        root.appendChild(subElem);
        SOAPHeaderElement headerElement = new SOAPHeaderElement(root);
        _call.addHeader(headerElement);
        ...
        _call.invoke();

    Tracing through the code for Call.invoke(), the header transmission portion is completely skipped. See below:

        public void invoke() throws AxisFault {

            ...

            // Determine client target service
            if (myService != null) {
                // If we have a SOAPService kicking around, use that directly
                msgContext.setService(myService);
            } else {
                if (portName != null) {   <--- This if block is executed because portname is set
                    // No explicit service.  If we have a target service name,
                    // try that.
                    msgContext.setTargetService(portName.getLocalPart());
                } else {   <--- The else block is skipped so headers are not added
                    // No direct config, so try the namespace of the first body.
                    reqMsg = msgContext.getRequestMessage();
                    reqEnv = reqMsg.getSOAPEnvelope();

                    // If we have headers to insert, do so now.
                    for (int i = 0 ; myHeaders != null && i < myHeaders.size() ; i++ )
                        reqEnv.addHeader((SOAPHeaderElement)myHeaders.get(i));
                    ...
                }

    Please let me know what is the recommended way to add a SOAP header in client code.

    Naresh Bhatia

Reply via email to