我用的是maven,需要添加以下内容
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-wsdl</artifactId>
<version>3.1.6</version>
</dependency>
<dependency>
<groupId>org.codehaus.xfire</groupId>
<artifactId>xfire-core</artifactId>
<version>1.2.6</version>
</dependency>
<dependency>
<groupId>org.apache.ws.xmlschema</groupId>
<artifactId>xmlschema-core</artifactId>
<version>2.2.1</version>
</dependency>
<dependency>
<groupId>org.codehaus.xfire</groupId>
<artifactId>xfire-aegis</artifactId>
<version>1.2.6</version>
</dependency>
直接上代码
import org.apache.axis.client.Call;
import org.apache.axis.client.Service;
import org.apache.axis.encoding.XMLType;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.codehaus.xfire.client.Client;
import javax.xml.namespace.QName;
import javax.xml.rpc.ServiceException;
import java.net.URL;
/**
* 使用xfire的方式调用webservice
* [@param](http://my.oschina.net/u/2303379) serviceURL 调用地址
* [@param](http://my.oschina.net/u/2303379) interfaceName 调用接口名称或方法名称
* [@param](http://my.oschina.net/u/2303379) paramValue 需要传送的值
* [@return](http://my.oschina.net/u/556800) 返回数组
*/
public static Object[] xfireSOAPClient(String serviceURL,String interfaceName,String paramValue){
Client client = null;
Object[] results =null;
try {
client = new Client(new URL(serviceURL));
results = client.invoke(interfaceName, new Object[] {paramValue});
} catch (Exception e) {
log.error("xfire request error ! {}",e.getMessage());
}
return results;
}
这样就可以直接调用了
来源:oschina
链接:https://my.oschina.net/u/79159/blog/712546