CXF Way
Public Staticobject[] invokeremotemethod (string URL, string method, object[] parameters) {jaxwsdynamicclientfactory DCF
=jaxwsdynamicclientfactory.newinstance (); if(!url.endswith ("WSDL") ) {URL+ = "? wsdl"; } org.apache.cxf.endpoint.Client Client=dcf.createclient (URL); Try{object[] objects=Client.invoke (method, parameters); returnobjects; } Catch(Exception e) {e.printstacktrace (); } return NULL; }
Maven Reference
<Dependency> <groupId>Org.apache.cxf</groupId> <Artifactid>Cxf-rt-frontend-jaxws</Artifactid> <version>3.1.5</version> </Dependency> <!--Https://mvnrepository.com/artifact/org.apache.cxf/cxf-core - <Dependency> <groupId>Org.apache.cxf</groupId> <Artifactid>Cxf-core</Artifactid> <version>3.1.5</version> </Dependency> <Dependency> <groupId>Org.apache.cxf</groupId> <Artifactid>Cxf-rt-transports-http</Artifactid> <version>3.1.5</version> </Dependency>
Disadvantage is low efficiency, slow call speed
Xfire Method Invocation
Public StaticString GetData (String Wsurl, String invoke, object[] objparams)throwsmalformedurlexception, Exception {URL URL=NewURL (Wsurl); HttpURLConnection Connection=(HttpURLConnection) url.openconnection (); Connection.connect (); Client Client=NewClient (Connection.getinputstream (), (Class)NULL); Client.setproperty ("Disable-keep-alive", "true"); Client.setproperty ("Disable.expect-continue", "true"); Client.seturl (Wsurl); Object[] Result=Client.invoke (Invoke, Objparams); String ResultStr= Result[0].tostring (); return". Equals (RESULTSTR)?" ": ResultStr; }
Maven Reference
<Dependency> <groupId>Org.codehaus.xfire</groupId> <Artifactid>Xfire-all</Artifactid> <version>${xfire.version}</version> <Exclusions> <exclusion> <groupId>Org.springframework</groupId> <Artifactid>Spring</Artifactid> </exclusion> </Exclusions> </Dependency>
The downside is that the jar package is too old to be easily conflicted with other packages
Java Dynamic Call WebService