【问题标题】:Retrieving correct data from WS in java在java中从WS中检索正确的数据
【发布时间】:2013-06-18 21:16:19
【问题描述】:

我在这个 WSDL 上运行了 wsimport

http://ws.dati.comune.milano.it/opendata/wsopendata.asmx?WSDL

并生成客户端 JAX-WS 类。

现在我想使用getOpenWifi

使用这个 sn-p :

        String message = " ";
        WSOpenData wsopendata = new WSOpenData();
        GetOpenWifiResult result = wsopendata.getWSOpenDataSoap().getOpenWifi(" ");
        List<Object> list = result.getContent();
        for (Iterator<Object> iterator = list.iterator(); iterator.hasNext();) {

            message += iterator.next().toString() + " ";
        }

我将message 获取为

 [NewDataSet: null] 

我认为我做错了什么,我该如何检索正确的数据集?

【问题讨论】:

    标签: java jax-ws wsimport


    【解决方案1】:

    当我用 SoapUI 调用它时,我得到类似的东西

        <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
       <soap:Body>
          <getOpenWifiResponse xmlns="http://comune.milano.it/">
             <getOpenWifiResult>
                <NewDataSet xmlns="">
                   <Table>
                      <ID>3</ID>
                      <Sito>Arco Della Pace</Sito>
                      <Zona>1</Zona>
                      <Attiva>1</Attiva>
                      <Codice>A0044</Codice>
                      <Coordinate>9.172460,45.475670,0.000000</Coordinate>
                   </Table>
                   <Table>
                      <ID>4</ID>
                      <Sito>Bastioni di Porta Nuova 23</Sito>
                      <Zona>1</Zona>
                      <Attiva>1</Attiva>
                      <Codice>E0725</Codice>
                      <Coordinate>9.192273,45.478577,0.000000</Coordinate>
                   </Table>
    

    我认为“NewDataSet”-Object 会有子对象“table”。检查生成的人工制品(我没有)

    €dit: 试试看

    import it.milano.comune.GetOpenWifiResponse.GetOpenWifiResult;
    import it.milano.comune.WSOpenData;
    
    import java.net.URL;
    
    import org.w3c.dom.Element;
    import org.w3c.dom.Node;
    import org.w3c.dom.NodeList;
    
    
    public class Test {
    
        /**
         * @param args
         */
        public static void main(String[] args) throws Exception {
            WSOpenData ws = new WSOpenData(new URL("http://ws.dati.comune.milano.it/opendata/wsopendata.asmx?WSDL"));
    
            GetOpenWifiResult rw = ws.getWSOpenDataSoap().getOpenWifi(" ");
            for (Object o : rw.getContent()) {
                System.out.println(o.getClass().getName());
                Element e = (Element) o;
                NodeList c = e.getChildNodes();
    
                System.out.println(c);
                for (int i = 0; i < c.getLength(); i++) {
                    Node table = c.item(i);
    
                    System.out.println("tab");
    
                    for (int i2 = 0; i2 < table.getChildNodes().getLength(); i2++) {
                        Node property = table.getChildNodes().item(i2);
                        System.out.println("\tp: " + property);
                    }
    
                }
    
            }
    
            long x = 1;
        }
    
    }
    

    它给了我

    com.sun.org.apache.xerces.internal.dom.ElementNSImpl
    [NewDataSet: null]
    tab
        p: [ID: null]
        p: [Sito: null]
        p: [Zona: null]
        p: [Attiva: null]
        p: [Codice: null]
        p: [Coordinate: null]
    tab
        p: [ID: null]
        p: [Sito: null]
        p: [Zona: null]
        p: [Attiva: null]
        p: [Codice: null]
        p: [Coordinate: null]
    tab
        p: [ID: null]
        p: [Sito: null]
        p: [Zona: null]
        p: [Attiva: null]
        p: [Codice: null]
        p: [Coordinate: null]
    tab
        p: [ID: null]
        p: [Sito: null]
        p: [Zona: null]
        p: [Attiva: null]
        p: [Codice: null]
        p: [Coordinate: null]
    [...]
    

    我敢肯定,如果您尝试一下,您将能够解决它

    【讨论】:

    • 我需要从 getOpenWifiResult 中提取 NewDataSet xml 但 OpenWifiResult 只有 List getContent() 方法
    • 坏消息:我生成了存根并进行了一些调试。列表中返回的对象属于“com.sun.org.apache.xerces.internal.dom.ElementNSImpl”类型。调试器说它们包含解析的内容 - 但我认为你必须自己手动转换类型
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-12-06
    • 1970-01-01
    • 1970-01-01
    • 2023-04-04
    • 1970-01-01
    • 2017-07-22
    相关资源
    最近更新 更多