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