SOAP / SAAJ error, please help me.

Hello.

I've done a simple WebService wich add 2 numbers.

When I use SAAJ, I obtain an error.

Here il my SOAP code :

import javax.xml.soap.*;

import javax.xml.namespace.QName;

import java.util.Iterator;

import java.net.URL;

publicclass Request{

publicstaticvoid main(String[] args){

try{

//Getting a SOAPConnection Object

SOAPConnectionFactory soapConnectionFactory = SOAPConnectionFactory.newInstance();

SOAPConnection connection = soapConnectionFactory.createConnection();

// Creating a message

MessageFactory factory = MessageFactory.newInstance();

SOAPMessage message = factory.createMessage();

SOAPHeader header = message.getSOAPHeader();

// Add content to body

SOAPBody body = message.getSOAPBody();

QName bodyName =new QName("http://localhost","additionner","myWS");

SOAPBodyElement bodyElement = body.addBodyElement(bodyName);

// Delete "header"

header.detachNode();

// Adding content

QName childname1 =new QName("http://localhost","valeur1","myWS");

bodyElement.addChildElement(childname1).addTextNode("5");

QName childname2 =new QName("http://localhost","valeur2","myWS");

bodyElement.addChildElement(childname2).addTextNode("6");

message.writeTo(System.out);

System.out.println("\n");

// call method who takes two arguments :

//message : message being sent

//endpoint : destination to which the message should go

URL endpoint =new URL ("http://localhost:8080/testWS/services/CalculerWS");

SOAPMessage response = connection.call(message, endpoint);

// Close connection

connection.close();

//Getting the content of the message

SOAPBody soapBody = response.getSOAPBody();

Iterator iterator = soapBody.getChildElements(bodyName);

bodyElement = (SOAPBodyElement)iterator.next();

String add = bodyElement.getValue();

// Display the returned value

System.out.print("The return value of server: ");

System.out.println(add);

}catch (Exception ex){

ex.printStackTrace();

}

}

}

And this is the error displays in the console :

java.util.NoSuchElementException

at com.sun.xml.messaging.saaj.soap.impl.ElementImpl$3.next(ElementImpl.java:723)

at Request.main(Request.java:49)

Have you got any idea to help me.

Thanks a lot.

[3874 byte] By [Chris_isimaa] at [2007-11-26 20:09:14]
# 1
check out line 49 where there's obviously something missing in the SOAP message that you're trying to retrieve from it outside a try/catch block.
jwentinga at 2007-7-9 23:12:18 > top of Java-index,Java Essentials,Java Programming...