How do I set the SOAP authentication header before calling a webservice method?

Posted on 2008-11-05
Last Modified: 2013-12-14
I'm using NetBeans and I was able to consume the web service wsdl.  It looks like it created all the classes.  I'm able to call one of the methods, but because it requires SOAP header authentication, I get a SOAP exception error.  How do I generate the SOAP Header before calling the GetCurrentTrips method?

Steve Cross
'here is what the SOAP envelope should look like

<SOAP-ENV:Envelope xmlns:SOAP-ENV="" xmlns:SOAP-ENC="" xmlns:xsi="" xmlns:xsd="">


		<m:TTMHeader xmlns:m="urn:TruckMateTypes">






		<m:TMobileCommHeader xmlns:m="urn:MobileCommImpl">





		<m:GetCurrentTrips xmlns:m="urn:MobileCommIntf-IMobileComm" SOAP-ENV:encodingStyle="">

			<ActiveTrips xsi:type="xsd:boolean">true</ActiveTrips>




<Here is my program.>

package com.fairrington.TruckMate.API;



 * @author SCross


public class IcommAPI {

    public static void main(String[] args) {

    try { // Call Web Service Operation

        ca.maddocks.tmapi.IMobileCommservice service = new ca.maddocks.tmapi.IMobileCommservice();

        ca.maddocks.tmapi.IMobileComm port = service.getIMobileCommPort();


       truckmatetypes.TTMHeader s = new truckmatetypes.TTMHeader();






       mobilecommimpl.TMobileCommHeader n = new mobilecommimpl.TMobileCommHeader();



        // TODO initialize WS operation arguments here

        boolean activeTrips = true;

                // TODO process result here

        mobilecommtypes.TCurrentTrips result = port.getCurrentTrips(activeTrips);

        System.out.println("Result = "+result);

    } catch (Exception ex)



      System.out.println("Failed " + ex );  // TODO handle custom exceptions here




Open in new window

Question by:fairrington
    LVL 23

    Accepted Solution

    I don't think you will be able to add soap headers for SOAP message generated via stubs you may have to write a separate client, which  constructs the SOAP message and pass.

    Author Comment

    I was able to figure this out using Netbeans IDE 6.1.  I had to create a message handler that intercepted the SOAP enevlope.  From there I was able to add the SOAP header with the user id/password the web service was looking for.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Find Ransomware Secrets With All-Source Analysis

    Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

    Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
    Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
    This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
    The viewer will receive an overview of the basics of CSS showing inline styles. In the head tags set up your style tags: (CODE) Reference the nav tag and set your properties.: (CODE) Set the reference for the UL element and styles for it to ensu…

    761 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    12 Experts available now in Live!

    Get 1:1 Help Now