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:

  1. 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); 
  2. using java stub generated wsdl, using wsdl2java.

  3. 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

Popular posts from this blog

linux - xterm copying to CLIPBOARD using copy-selection causes automatic updating of CLIPBOARD upon mouse selection -

c++ - qgraphicsview horizontal scrolling always has a vertical delta -