whycxzp
2024-10-21 13d2d9bc303a793d47198de8416447be113d7bbc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
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);
        }
 
 
    }
}