Simply consuming a web service in Java -
i have simple soap web service need consume java client. easiest way accomplish without using third party libraries? requirement host , port read web.xml before every call ws.
i can recommend cxf library. using have several options calling web services:
use dynamic proxy calling (don't need make java stubs using wsdl2java).
dynamicclientfactory dcf = dynamicclientfactory.newinstance(); client client = dcf.createclient("http://admin:password@localhost:8080"+ "/services/myservice?wsdl"); object[] = client.invoke("test", ""); system.out.println(a);
using java stub generated wsdl, using wsdl2java.
if server created using cxf can reuse interface code directly (instead of using wsdl2java on wsdl created interface!)
for both #2 , #3, following code exemplifies cxf usage:
jaxwsproxyfactorybean factory = new jaxwsproxyfactorybean(); factory.setaddress("http://admin:password@localhost:8080/services/myservice"); factory.setserviceclass(itest.class); itest client = (itest) factory.create(); client.test();
Comments
Post a Comment