Dynamic web service client from wsdl

半腔热情 提交于 2021-02-11 06:16:51

问题


One of my system need to invoke SOAP based webservices. As of now, for every new webservices, I generate Java stubs from the provided WSDL file and redeploy the web application with new webservice consumer code. Is there a good approach to dynamically create a webservice client that can invoke the methods from the provided WSDL files? All I am expecting is

  • put the WSDL file in the location that can be accessed by the web application
  • invoke the Servlet with a keyword having the wsdl file name, and other params required for the webservice method.

Can the Apache CXF help in this? I read in a post, generating wsdl2java in the runtime and loading the classes, over a time, can exhaust the pemgen memory space.


回答1:


You should look here : http://cxf.apache.org/docs/dynamic-clients.html This is exactly that.

here an example:

ClientImpl client = (ClientImpl)doc.getClientFromWsdl("http://myurl:8080/DataCentersWS?wsdl");
String operationName = "getVirtualisationManagerUuid";
BindingOperationInfo op = doc.getOperation(client, operationName);
List<MessagePartInfo> messagesParts = op.getInput().getMessageParts();
Object[] params = new Object[messagesParts.size()];
/* feed yours params here (this feeding was heavy in my code */
Object[] res = client.invoke(op, params);

There is many other examples in the source distribution of cxf.



来源:https://stackoverflow.com/questions/26354639/dynamic-web-service-client-from-wsdl

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!