package com.whyc.webService;
|
|
import org.apache.cxf.endpoint.Client;
|
import org.apache.cxf.jaxws.endpoint.dynamic.JaxWsDynamicClientFactory;
|
|
import javax.xml.namespace.QName;
|
import javax.xml.transform.TransformerFactory;
|
import javax.xml.transform.stream.StreamSource;
|
import java.io.ByteArrayInputStream;
|
import java.io.InputStream;
|
|
public class WsClient {
|
public static void main(String[] args) throws Exception {
|
String url = "http://localhost:8919/fg/ws/IMS_Service?wsdl";
|
String param = "<?xml version=\"1.0\" encoding=\"gb2312\"?>\n" +
|
"<info>\n" +
|
"\t<CorporationCode>地域代码</CorporationCode>\n" +
|
"<!--传入的指标名称可以为一个或多个-->\n" +
|
"<Time>时间值</Time>\n" +
|
"<api name=\"指标名称1\"></api>\n" +
|
"<api name=\"指标名称2\"></api>\t\n" +
|
"<api name=\"指标名称n\"></api>\n" +
|
"</info>";
|
JaxWsDynamicClientFactory dcf = JaxWsDynamicClientFactory.newInstance();
|
Client client = dcf.createClient(url);
|
QName qName = new QName("http://webService.whyc.com/", "getKPIValue");
|
|
TransformerFactory tf = TransformerFactory.newInstance();
|
try (InputStream is = new ByteArrayInputStream(param.getBytes("gb2312"))) {
|
StreamSource source = new StreamSource(is);
|
Object[] value = client.invoke(qName, source);
|
System.out.println(value[0]);
|
} catch (Exception e) {
|
throw new RuntimeException("Convert XML string to Source failed", e);
|
}
|
|
|
}
|
}
|