I am dynamically consuming a webservice by JAX-WS API. Instantiating service class and invoking by web service by reflection API.
Though the expected and actual argument is same its getting "Argument type mismatch" Exception.
Quick help is appreciated.
Class<?>[] paramTypes = serviceClassMethod.getParameterTypes();
System.out.println("Expected Param Class : "+paramTypes[0].getName());
System.out.println("Actual Param Class : "+reqVals[0].getClass());
System.out.println("Expected number : "+paramTypes.length);
System.out.println("Actual number : "+reqVals.length);
Object wsResponse = serviceClassMethod.invoke(service, reqVals);
System.out.println("Invocation successful...");
Output:
Expected Param Class : com.bla.bla.ws.User
Actual Param Class : class com.bla.bla.ws.User
Expected number : 1
Actual number : 1
This sounds like a classloading issue. The JRE treats the same class loaded by different classloaders as different class. It depends on how you create your parameter object. You can test this using:
paramTypes[0].equals(reqVals[0].getClass())
If this is not true, you are using two different classes.
A solution would be to ensure your parameter object is created with the correct class using paramTypes[0].newInstance();
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.