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?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Siva Prasanna KumarPrincipal 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.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
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.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Editors IDEs

From novice to tech pro — start learning today.