Problem when invoking java web service. the serializer / deserializer for the parameter is ambiguous because its class could not be determined

1

I'm trying to invoke a web service through java, but when I run the code I get an error that says:

  

the serializer / deserializer for the parameter number: 0, name:   "{ link } consultBooksResponse", type:   "{ link } consultBooksResponse", is ambiguous because it does not   You could determine your class

For what I read is a serialization problem but I do not know how to solve it because I do not have access to the web service code, but I just want to implement a client for it.

The code I am implementing is:

ServiceFactory sf = ServiceFactory.newInstance();
Service serv = sf.createService(
new URL("http://localhost:8080/WSLibreria/libreria?WSDL"),
new QName("http://servicios/", "libreria"));
Call call = serv.createCall(
    new QName("http://servicios/", "libreriaPort"),
    new QName("http://servicios/", "consultarLibros")
);
String result = (String) call.invoke(
    new Object[]{ "novela" }
);  

I would appreciate if you can help me solve this.

    
asked by Luis Espinel Fuentes 28.09.2016 в 04:15
source

1 answer

1

I have solved my problem by using the utility that offers java wsimport and a little reflection.

The wsimport utility creates a package with all the necessary classes to consume a web service, this is done simply with the help of the WSDL file of the web service to be consumed.

After creating these files I used the reflection capabilities in java to be able to execute the service. Since what I want is to create a client for any type of service and be able to execute it.

Here is a small example of how I solved it

I created from java a call to wsimport. where I give the URL of the web service wsdl and the -keep option allows me to keep the generated .java and .class files

Runtime.getRuntime (). exec ("wsimport -keep link ");

The wsimport creates a package called services with all the .java and .class files

After that use reflection to be able to execute the service.

    Class clase=Class.forName("servicios.Libreria_Service");
    Object service=(Object)clase.newInstance();
    Class clase2=Class.forName("servicios.Libreria");        
    Method metodoGetPort=clase.getMethod("getLibreriaPort");      
    Object obj2=metodoGetPort.invoke(service,null);                 
    Method[] metodosClase2=clase2.getMethods();
    for(Method metodo : metodosClase2){
        if(metodo.getName().equals("consultarLibros")){
            out.print("Encontró el metodo<br>");        
            String resultado=(String) metodo.invoke(obj2,"novela");                
            out.print("rsultado  :"+resultado);
        }
    }
    
answered by 06.10.2016 в 04:02