Java Dynamic Call WebService

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.