JAXM Client for JAX-RPC Web Service

From: Ramasamy S/O Valliappan <rama_at_SIMTECH.A-STAR.EDU.SG>
Date: Fri, 18 Jul 2003 10:18:50 +0800

Hi Guys

The following is my JAX-RPC Hello Service WSDL

<?xml version="1.0" encoding="UTF-8" ?>
- <definitions xmlns="" xmlns:tns="http://com.test/wsdl/MyHello" xmlns:xsd="" xmlns:soap="" name="MyHello" targetNamespace="http://com.test/wsdl/MyHello">
<types />
- <message name="HelloIF_sayHello">
<part name="String_1" type="xsd:string" />
- <message name="HelloIF_sayHelloResponse">
<part name="result" type="xsd:string" />
- <portType name="HelloIF">
- <operation name="sayHello" parameterOrder="String_1">
<input message="tns:HelloIF_sayHello" />
<output message="tns:HelloIF_sayHelloResponse" />
- <binding name="HelloIFBinding" type="tns:HelloIF">
- <operation name="sayHello">
- <input>
<soap:body encodingStyle="" use="encoded" namespace="http://com.test/wsdl/MyHello" />
- <output>
<soap:body encodingStyle="" use="encoded" namespace="http://com.test/wsdl/MyHello" />
<soap:operation soapAction="" />
<soap:binding transport="" style="rpc" />
- <service name="MyHello">
- <port name="HelloIFPort" binding="tns:HelloIFBinding">
<soap:address xmlns:wsdl="" location="http://localhost:8080/hello-jaxrpc/hello" />

The following is my jaxm hello client for the above service (please correct the code if any errors)

package hello;

import java.util.*;

import javax.servlet.http.*;
import javax.servlet.*;

import javax.xml.soap.*;

import javax.activation.*;
import org.apache.commons.logging.*;

public class JaxmHelloClient {
    static Log logger = LogFactory.getFactory().getInstance("Samples/Hello");

    // Connection to send messages.
    static SOAPConnection con;
    static SOAPMessage msg;
    static SOAPMessage reply;
    public static void main(String[] args) {
      try {
          SOAPConnectionFactory scf = SOAPConnectionFactory.newInstance();
          con = scf.createConnection();
        } catch(Exception e) {
          logger.error("Unable to open a SOAPConnection", e);
        String retval ="<html><H4>";

        try {
            // Create a message factory.
            MessageFactory mf = MessageFactory.newInstance();

            // Create a message from the message factory.
            msg = mf.createMessage();

            // Message creation takes care of creating the SOAPPart - a
            // required part of the message as per the SOAP 1.1
            // specification.
            SOAPPart sp = msg.getSOAPPart();

            // Retrieve the envelope from the soap part to start building
            // the soap message.
            SOAPEnvelope envelope = sp.getEnvelope();

            // Create a soap header from the envelope.
            SOAPHeader hdr = envelope.getHeader();

            // Create a soap body from the envelope.
            SOAPBody bdy = envelope.getBody();

            // Add a soap body element to the soap body
            SOAPBodyElement gltp = bdy.addBodyElement(envelope.createName("sayHello"));


            // Create an endpoint for the recipient of the message.
            URL urlEndpoint = new URL("http://localhost:8080/hello-jaxrpc/hello");

            System.err.println("Sending message to URL: "+urlEndpoint);
            System.err.println("Sent message is logged in \"sent.msg\"");

            retval += " Sent message (check \"sent.msg\") and ";

            FileOutputStream sentFile = new FileOutputStream("sent.msg");

            // Send the message to the provider using the connection.
            reply =, urlEndpoint);

            if (reply != null) {
                FileOutputStream replyFile = new FileOutputStream("reply.msg");
                System.err.println("Reply logged in \"reply.msg\"");
                retval += " received reply (check \"reply.msg\"). </H4></html>";

            } else {
                System.err.println("No reply");
                retval += " no reply was received. </H4></html>";

        } catch(Throwable e) {
            logger.error("Error in constructing or sending message "
            retval += " There was an error " +
            "in constructing or sending message. </H4></html>";

        try {
            System.out.println("<br><b> SOAP Request Message : </b><br><br>".getBytes());
            System.out.println("<br><br><b>SOAP Response Message : </b><br><br>".getBytes());
        } catch (Exception e) {
            logger.error( "Error in outputting servlet response "
            + e.getMessage());

How can I write a JAXM-Client to invoke this web service or any other web service ? Is it possible for a JAXMClient to invoke a JAX-RPC Service ?