*
The moose likes Web Services and the fly likes Webservice Help! Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Web Services
Bookmark "Webservice Help!" Watch "Webservice Help!" New topic
Author

Webservice Help!

Chandramouli Jambunathan
Greenhorn

Joined: Mar 17, 2009
Posts: 8
Hi,

I have created one Webservice just to add 2 number and return the sum value. I can able to receive the sum value as integer as-well-as as SOAPMessage. In the webservide i just return the integer value, but in the client side i can able able to receive as SOAPMessage as well.
But, when i return the response sum data as SOAPMessage, i am not able to receive it in the client, it says return sum as empty. Please check the below code and let me know where is the problem.

Client:
-------
public class Main {


/**

* @param args the command line arguments

*/

public static void main(String[] args) {



try {

// Call Web Service Operation

//calculatorws_client_application.CalculatorWSService service = new calculatorws_client_application.CalculatorWSService();

//calculatorws_client_application.CalculatorWS port = service.getCalculatorWSPort();

// TODO initialize WS operation arguments here

//int param1 = 2;

//int param2 = 3;

// TODO process result here

//int result = port.add(param1, param2);

//System.out.println("Result = "+result);


//First create the connection

SOAPConnectionFactory soapConnFactory =

SOAPConnectionFactory.newInstance();

SOAPConnection connection =

soapConnFactory.createConnection();

MessageFactory messageFactory = MessageFactory.newInstance();

SOAPMessage message = messageFactory.createMessage();



//Create objects for the message parts

SOAPPart soapPart = message.getSOAPPart();

SOAPEnvelope envelope = soapPart.getEnvelope();

SOAPBody body = envelope.getBody();


//Populate the body

//Create the main element and namespace

SOAPElement bodyElement =

body.addChildElement(envelope.createName("add" ,

"ns2",

"http://calculator.me.org/"));

//Add content

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

bodyElement.addChildElement("param2").addTextNode("10");


//Save the message

message.saveChanges();

//Check the input

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

message.writeTo(System.out);

System.out.println();


//Send the message and get a reply

//Set the destination

String destination =

"http://localhost:8080/CalculatorWSApplication/CalculatorWSService?WSDL";

//Send the message

SOAPMessage replyMessage = connection.call(message, destination);



System.out.println("Reply Body::"+replyMessage.toString());

SOAPBody soapBody = replyMessage.getSOAPBody();

System.out.println("soapBody.getTextContent()::"+soapBody.getTextContent());

System.out.println("XML Reply Message...");

replyMessage.writeTo(System.out);

//Close the connection

connection.close();



} catch (Exception ex) {

// TODO handle custom exceptions here

}

}

}

Webservice:
--------------

@WebService()

public class CalculatorWS {


/**

* Web service operation

*/

@WebMethod(operationName = "add")

public SOAPMessage add(@WebParam(name = "param1")

int param1, @WebParam(name = "param2")

int param2) {

//TODO write your implementation code here:

SOAPMessage message = null;

try {

MessageFactory messageFactory = MessageFactory.newInstance();

message = messageFactory.createMessage();

//Create objects for the message parts

SOAPPart soapPart = message.getSOAPPart();

SOAPEnvelope envelope = soapPart.getEnvelope();

SOAPBody body = envelope.getBody();

//Populate the body

//Create the main element and namespace

SOAPElement bodyElement =

body.addChildElement(envelope.createName("addResponse" ,

"ns2",

""));

//Add content

int result = param1 + param2;

bodyElement.addChildElement("return").addTextNode(""+result);

//bodyElement.addChildElement("param2").addTextNode("10");


//Save the message

message.saveChanges();


//Check the input

System.out.println("Response Message:\n");

message.writeTo(System.out);

System.out.println();


//return (param1+param2);

}

catch(Exception ex) {

System.out.println("Exception:::"+ex);

}
return message;

}
}
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Webservice Help!