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

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

Who is Participating?
Siva Prasanna KumarConnect With a Mentor Principal Solutions ArchitectCommented:
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.
fairringtonAuthor Commented:
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.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.