Ver Mensaje Individual
  #5 (permalink)  
Antiguo 26/06/2013, 10:29
leonardo_josue
Colaborador
 
Fecha de Ingreso: enero-2007
Ubicación: México
Mensajes: 2.097
Antigüedad: 17 años, 4 meses
Puntos: 447
Respuesta: Cómo consumir un web service JAX-WS con JDeveloper 10g

Hola de nuevo chuidiang:

Código:
Ese mismo cliente de axis debería debería servirte para invocar un web service hecho con cualquier otra herramienta (jax-ws).
Ese es el detalle... que el cliente AXIS no funciona para invocar el WS de JAX-WS...

Me explico... El ws que estoy tratando de invocar es bastante sencillo, es de hecho el ejemplo "HolaMundo" que viene por defecto... mi clase la tengo definida así:

Código Java:
Ver original
  1. package mx.org.ws.publicar;
  2.  
  3. import javax.jws.WebService;
  4. import javax.jws.WebMethod;
  5. import javax.jws.WebParam;
  6.  
  7. @WebService(serviceName = "HolaMundo")
  8. public class HolaMundo {
  9.  
  10.     @WebMethod(operationName = "hello")
  11.     public String hello(@WebParam(name = "name") String txt) {
  12.         return "Hello " + txt + " !";
  13.     }
  14. }

Al traer el WSDL (http://localhost:8084/HolaMundo/HolaMundo?wsdl)
me muestra lo siguiente:

Código XML:
Ver original
  1. <!--
  2. Published by JAX-WS RI at http://jax-ws.dev.java.net. RI's version is JAX-WS RI 2.2-hudson-740-.
  3. -->
  4. <!--
  5. Generated by JAX-WS RI at http://jax-ws.dev.java.net. RI's version is JAX-WS RI 2.2-hudson-740-.
  6. -->
  7. <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">
  8. <types>
  9. <xsd:schema>
  10. <xsd:import namespace="http://publicar.ws.org.mx/" schemaLocation="http://localhost:8084/HolaMundo/HolaMundo?xsd=1"/>
  11. </xsd:schema>
  12. </types>
  13. <message name="hello">
  14. <part name="parameters" element="tns:hello"/>
  15. </message>
  16. <message name="helloResponse">
  17. <part name="parameters" element="tns:helloResponse"/>
  18. </message>
  19. <portType name="HolaMundo">
  20. <operation name="hello">
  21. <input wsam:Action="http://publicar.ws.org.mx/HolaMundo/helloRequest" message="tns:hello"/>
  22. <output wsam:Action="http://publicar.ws.org.mx/HolaMundo/helloResponse" message="tns:helloResponse"/>
  23. </operation>
  24. </portType>
  25. <binding name="HolaMundoPortBinding" type="tns:HolaMundo">
  26. <soap:binding transport="http://schemas.xmlsoap.org/soap/http" style="document"/>
  27. <operation name="hello">
  28. <soap:operation soapAction=""/>
  29. <input>
  30. <soap:body use="literal"/>
  31. </input>
  32. <output>
  33. <soap:body use="literal"/>
  34. </output>
  35. </operation>
  36. </binding>
  37. <service name="HolaMundo">
  38. <port name="HolaMundoPort" binding="tns:HolaMundoPortBinding">
  39. <soap:address location="http://localhost:8084/HolaMundo/HolaMundo"/>
  40. </port>
  41. </service>
  42. </definitions>

Es decir, el WS está activo y funcionando... al tratar de utilizar el cliente AXIS desde JDeveloper 10g, lo hago de la siguiente manera:

Código Java:
Ver original
  1. package clientews;
  2.  
  3. import org.apache.axis.client.Call;
  4. import org.apache.axis.client.Service;
  5.  
  6. public class cliente {
  7.     public cliente() {
  8.     }
  9.    
  10.     public static String consumir(Object[] parametros){
  11.         String regresar = null;
  12.         Service service = null;  
  13.         Call call       = null;
  14.         String endpoint = null;
  15.         try {
  16.           endpoint = "http://localhost:8084/HolaMundo/HolaMundo";          
  17.           service = new Service();
  18.           call = (Call) service.createCall();
  19.           call.setTargetEndpointAddress(new java.net.URL(endpoint));
  20.           call.setOperationName("hello");        
  21.           regresar=String.valueOf(call.invoke(parametros));          
  22.         }// try
  23.         catch (Exception e) {
  24.           e.printStackTrace();
  25.         }// catch
  26.         finally {
  27.           return regresar;
  28.         }// finally
  29.       }
  30.  
  31.     public static void main(String[] args) {
  32.         try {            
  33.             String parametro = "José";
  34.             String respuesta = consumir(new Object[]{parametro});
  35.             System.out.println("respuesta: --->" + respuesta);
  36.         } catch (Exception e) {
  37.             System.err.println(e.toString());
  38.         }
  39.     }
  40. }

Sin embargo, al ejecutar la clase, me está arrojando el siguiente error:

Código:
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
Este mismo método, publicado en AXIS 1.4 lo tengo de la siguiente manera:

Código Java:
Ver original
  1. package mx.org.ws.publicar;
  2.  
  3. public class HolaMundo {
  4.     public HolaMundo() {
  5.     }
  6.    
  7.     /**
  8.      * @webmethod
  9.      */
  10.     public String hello(String txt) {
  11.         return "Hello " + txt + " !";
  12.     }
  13. }

al traer su WSDL (http://localhost:8988/Pruebas/services/HolaMundo?wsdl) me trae lo siguiente:

Código XML:
Ver original
  1. <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">
  2. <!--
  3. WSDL created by Apache Axis version: 1.4
  4. Built on Apr 22, 2006 (06:55:48 PDT)
  5. -->
  6. <message name="helloRequest">
  7. <part name="txt" type="xsd:string"/>
  8. </message>
  9. <message name="helloResponse">
  10. <part name="helloReturn" type="xsd:string"/>
  11. </message>
  12. <portType name="HolaMundo">
  13. <operation name="hello" parameterOrder="txt">
  14. <input name="helloRequest" message="impl:helloRequest"/>
  15. <output name="helloResponse" message="impl:helloResponse"/>
  16. </operation>
  17. </portType>
  18. <binding name="HolaMundoSoapBinding" type="impl:HolaMundo">
  19. <wsdlsoap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http"/>
  20. <operation name="hello">
  21. <wsdlsoap:operation soapAction=""/>
  22. <input name="helloRequest">
  23. <wsdlsoap:body use="encoded" namespace="http://publicar.ws.org.mx" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
  24. </input>
  25. <output name="helloResponse">
  26. <wsdlsoap:body use="encoded" namespace="http://localhost:8988/Pruebas/services/HolaMundo" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
  27. </output>
  28. </operation>
  29. </binding>
  30. <service name="HolaMundoService">
  31. <port name="HolaMundo" binding="impl:HolaMundoSoapBinding">
  32. <wsdlsoap:address location="http://localhost:8988/Pruebas/services/HolaMundo"/>
  33. </port>
  34. </service>
  35. </definitions>

Al utilizar el cliente de AXIS, cambiando la URL, si hace la invocación y funciona perfectamente:

Código Java:
Ver original
  1. package clientews;
  2.  
  3. import org.apache.axis.client.Call;
  4. import org.apache.axis.client.Service;
  5.  
  6. public class cliente {
  7.     public cliente() {
  8.     }
  9.    
  10.     public static String consumir(Object[] parametros){
  11.         String regresar = null;
  12.         Service service = null;  
  13.         Call call       = null;
  14.         String endpoint = null;
  15.         try {
  16.           endpoint = "http://localhost:8988/Pruebas/services/HolaMundo";          
  17.           service = new Service();
  18.           call = (Call) service.createCall();
  19.           call.setTargetEndpointAddress(new java.net.URL(endpoint));
  20.           call.setOperationName("hello");        
  21.           regresar=String.valueOf(call.invoke(parametros));          
  22.         }// try
  23.         catch (Exception e) {
  24.           e.printStackTrace();
  25.         }// catch
  26.         finally {
  27.           return regresar;
  28.         }// finally
  29.       }
  30.  
  31.     public static void main(String[] args) {
  32.         try {            
  33.             String parametro = "José";
  34.             String respuesta = consumir(new Object[]{parametro});
  35.             System.out.println("respuesta: --->" + respuesta);
  36.         } catch (Exception e) {
  37.             System.err.println(e.toString());
  38.         }
  39.     }
  40. }

el resultado es

Código:
respuesta: --->Hello José !
Por lo tanto, lo que me dices de que el cliente de AXIS debería servir para invocar cualquier otro servicio es incorrecto

No sé si en realidad estoy haciendo algo mal... la verdad es que estoy bastante perdido con este problema.

Saludos y espero que me puedas echar la mano con alguna pista.
Leo.