Skip to main content

How can I do a WS using JAX-WS than works in an Axis Client?

Please note these java.net forums are being decommissioned and use the new and improved forums at https://community.oracle.com/community/java.
1 reply [Last post]
leonardo_josue
Offline
Joined: 2013-06-26

Hi everybody...

I'm trying to do a simple Hello World Web Service using JAX-WS than can be called by an Axis 1.4 client... I'm working with Netbeans 7.3 and a got this.

package mx.org.ws.publicar; 

import javax.jws.WebService;
import javax.jws.WebMethod;
import javax.jws.WebParam;

@WebService(serviceName = "HolaMundo")
public class HolaMundo {

@WebMethod(operationName = "hello")
public String hello(@WebParam(name = "name") String txt) {
return "Hello " + txt + " !";
}
}

When I browse the URL for WS (http://localhost:8084/HolaMundo/HolaMundo?wsdl) I got something like this:

<!-- 
Published by JAX-WS RI at http://jax-ws.dev.java.net. RI's version is JAX-WS RI 2.2-hudson-740-.
-->
<!--
Generated by JAX-WS RI at http://jax-ws.dev.java.net. RI's version is JAX-WS RI 2.2-hudson-740-.
-->
<definitions xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" xmlns:wsp="http://www.w3.org/ns/ws-policy" xmlns:wsp1_2="http://schemas.xmlsoap.org/ws/2004/09/policy" xmlns:wsam="http://www.w3.org/2007/05/addressing/metadata" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tns="http://publicar.ws.org.mx/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://schemas.xmlsoap.org/wsdl/" targetNamespace="http://publicar.ws.org.mx/" name="HolaMundo">
<types>
<xsd:schema>
<xsd:import namespace="http://publicar.ws.org.mx/" schemaLocation="http://localhost:8084/HolaMundo/HolaMundo?xsd=1"/>
</xsd:schema>
</types>
<message name="hello">
<part name="parameters" element="tns:hello"/>
</message>
<message name="helloResponse">
<part name="parameters" element="tns:helloResponse"/>
</message>
<portType name="HolaMundo">
<operation name="hello">
<input wsam:Action="http://publicar.ws.org.mx/HolaMundo/helloRequest" message="tns:hello"/>
<output wsam:Action="http://publicar.ws.org.mx/HolaMundo/helloResponse" message="tns:helloResponse"/>
</operation>
</portType>
<binding name="HolaMundoPortBinding" type="tns:HolaMundo">
<soap:binding transport="http://schemas.xmlsoap.org/soap/http" style="document"/>
<operation name="hello">
<soap:operation soapAction=""/>
<input>
<soap:body use="literal"/>
</input>
<output>
<soap:body use="literal"/>
</output>
</operation>
</binding>
<service name="HolaMundo">
<port name="HolaMundoPort" binding="tns:HolaMundoPortBinding">
<soap:address location="http://localhost:8084/HolaMundo/HolaMundo"/>
</port>
</service>
</definitions>

A few of customers has Axis 1.4 client's to comsume the Web service... like this.

package clientews; 
 
import org.apache.axis.client.Call;
import org.apache.axis.client.Service;
 
public class cliente {
    public cliente() {
    }
   
    public static String consumir(Object[] parametros){
        String regresar = null;
        Service service = null;   
        Call call       = null;
        String endpoint = null;
        try {
          endpoint = "http://localhost:8084/HolaMundo/HolaMundo";         
          service = new Service();
          call = (Call) service.createCall();
          call.setTargetEndpointAddress(new java.net.URL(endpoint));
          call.setOperationName("hello");         
          regresar=String.valueOf(call.invoke(parametros));         
        }// try
        catch (Exception e) {
          e.printStackTrace();
        }// catch
        finally {
          return regresar;
        }// finally
      }
 
    public static void main(String[] args) {
        try {           
            String parametro = "José";
            String respuesta = consumir(new Object[]{parametro});
            System.out.println("respuesta: --->" + respuesta);
        } catch (Exception e) {
            System.err.println(e.toString());
        }
    }
}

However, I try to ran this class I got this error message:

AxisFault 
faultCode: {http://schemas.xmlsoap.org/soap/envelope/}Client
faultSubcode:
faultString: Cannot find dispatch method for {}hello
faultActor:
faultNode:
faultDetail:
   {http://xml.apache.org/axis/}stackTrace:Cannot find dispatch method for {}hello

When I use Axis 1.4 to deploy de same WS I don't have any problem...

package mx.org.ws.publicar; 
 
public class HolaMundo {
    public HolaMundo() {
    }
   
    /**
     * @webmethod
     */
    public String hello(String txt) {
        return "Hello " + txt + " !";
    }
}

When I Bowse the URL for that WS (http://localhost:8988/Pruebas/services/HolaMundo?wsdl) I got this:

<definitions xmlns="http://schemas.xmlsoap.org/wsdl/" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:apachesoap="http://xml.apache.org/xml-soap" xmlns:impl="http://localhost:8988/Pruebas/services/HolaMundo" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:wsdlsoap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:intf="http://localhost:8988/Pruebas/services/HolaMundo" targetNamespace="http://localhost:8988/Pruebas/services/HolaMundo"> 
<!--
WSDL created by Apache Axis version: 1.4
Built on Apr 22, 2006 (06:55:48 PDT)
-->
<message name="helloRequest">
<part name="txt" type="xsd:string"/>
</message>
<message name="helloResponse">
<part name="helloReturn" type="xsd:string"/>
</message>
<portType name="HolaMundo">
<operation name="hello" parameterOrder="txt">
<input name="helloRequest" message="impl:helloRequest"/>
<output name="helloResponse" message="impl:helloResponse"/>
</operation>
</portType>
<binding name="HolaMundoSoapBinding" type="impl:HolaMundo">
<wsdlsoap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http"/>
<operation name="hello">
<wsdlsoap:operation soapAction=""/>
<input name="helloRequest">
<wsdlsoap:body use="encoded" namespace="http://publicar.ws.org.mx" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
</input>
<output name="helloResponse">
<wsdlsoap:body use="encoded" namespace="http://localhost:8988/Pruebas/services/HolaMundo" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
</output>
</operation>
</binding>
<service name="HolaMundoService">
<port name="HolaMundo" binding="impl:HolaMundoSoapBinding">
<wsdlsoap:address location="http://localhost:8988/Pruebas/services/HolaMundo"/>
</port>
</service>
</definitions>

The same client, with this URL works without problems:

package clientews; 
 
import org.apache.axis.client.Call;
import org.apache.axis.client.Service;
 
public class cliente {
    public cliente() {
    }
   
    public static String consumir(Object[] parametros){
        String regresar = null;
        Service service = null;   
        Call call       = null;
        String endpoint = null;
        try {
          endpoint = "http://localhost:8988/Pruebas/services/HolaMundo";         
          service = new Service();
          call = (Call) service.createCall();
          call.setTargetEndpointAddress(new java.net.URL(endpoint));
          call.setOperationName("hello");         
          regresar=String.valueOf(call.invoke(parametros));         
        }// try
        catch (Exception e) {
          e.printStackTrace();
        }// catch
        finally {
          return regresar;
        }// finally
      }
 
    public static void main(String[] args) {
        try {           
            String parametro = "José";
            String respuesta = consumir(new Object[]{parametro});
            System.out.println("respuesta: --->" + respuesta);
        } catch (Exception e) {
            System.err.println(e.toString());
        }
    }
}

The result of ran the class is this:

respuesta: --->Hello José !

So, What is wrong? How can I fix this problem.

Best regards
Leo.

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
leonardo_josue
Offline
Joined: 2013-06-26

Hi everybody...

I find a possible solution for my problem, but it isn't exactly what I want...

In this page I find another way to invoce the Web Service from Axis 1.4 client:

http://axis.apache.org/axis2/java/core/docs/migration.html

ie instead of doing this:

call.setOperationName("hello");

Must do especify the namespace in the constuctor, like this:

call.setOperationName(new QName("http://localhost:8988/Pruebas/services/HolaMundo", "hello"));

However, this solution means that customers who consume the web service have to modify their code, which is not feasible at all.

The question remains the same, is there any way to modify the Web Service to be called from Axis 1.4 client without having to make any changes?

Best Regards
Leo.