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?

Thanks,
Steve Cross
'here is what the SOAP envelope should look like
 
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
	<SOAP-ENV:Header>
		<m:TTMHeader xmlns:m="urn:TruckMateTypes">
			<DSN>DSN</DSN>
			<Password>password</Password>
			<Schema>SCHEMA</Schema>
			<Username>USER</Username>
		</m:TTMHeader>
		<m:TMobileCommHeader xmlns:m="urn:MobileCommImpl">
			<NetworkID>Q</NetworkID>
		</m:TMobileCommHeader>
	</SOAP-ENV:Header>
	<SOAP-ENV:Body>
		<m:GetCurrentTrips xmlns:m="urn:MobileCommIntf-IMobileComm" SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
			<ActiveTrips xsi:type="xsd:boolean">true</ActiveTrips>
		</m:GetCurrentTrips>
	</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
 
<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();
       s.setDSN("DSN");
       s.setPassword("password");
       s.setSchema("schema");
       s.setUsername("user");
 
       
       mobilecommimpl.TMobileCommHeader n = new mobilecommimpl.TMobileCommHeader();
       n.setNetworkID("Q");
        
        // 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

fairringtonAsked:
Who is Participating?

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

x
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.
0

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.
0
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.