Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

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

Posted on 2008-11-05
2
Medium Priority
?
7,292 Views
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?

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

0
Comment
Question by:fairrington
2 Comments
 
LVL 23

Accepted Solution

by:
Siva Prasanna Kumar earned 1500 total points
ID: 22927790
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
 

Author Comment

by:fairrington
ID: 23008752
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

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
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 …
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
Suggested Courses
Course of the Month20 days, 20 hours left to enroll

810 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