Android 調用webservice並解析

這是調用webService的具體方法java

private final static String nameSpace="http://tempuri.org/";
    private final static String url = "http://10.188.65.139/BizNavi_Link_Phone/Service.asmx?wsdl";
    
    public static List<WaitModel> CallWebService1() {
        // 調用webservice的具體方法        
        String nameSpace = "http://tempuri.org/";
        String methodName = "queryProcXml1";
        String soapAction = "http://tempuri.org/"+methodName;
        String url = "http://10.188.65.139/BizNavi_Link_Phone/Service.asmx?wsdl";// 後面加不加那個?wsdl參數影響都不大
        // 創建webservice鏈接對象
        HttpTransportSE transport = new HttpTransportSE(url);
//        transport.debug = false;// 是不是調試模式
        transport.debug = true;// 是不是調試模式
        // 設置鏈接參數
        SoapObject soapObject = new SoapObject(nameSpace, methodName);
        String paraNames []={"@in_EMPLOYEE_ID1"};
        String paraValues []  ={"109"};
                
        soapObject.addProperty("procName", "AFI02_HOME_GET_WAITING");        
        soapObject.addProperty("ret", 0);
        
        // 設置返回參數
        SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
                SoapEnvelope.VER11);// soap協議版本必須用SoapEnvelope.VER11(Soap V1.1)
        envelope.dotNet = true;// 注意:這個屬性是對dotnetwebservice協議的支持,若是dotnet的webservice
                                // 不指定rpc方式則用true不然要用false
        envelope.bodyOut = soapObject;//千萬注意!!
        
        envelope.setOutputSoapObject(soapObject);// 設置請求參數        
        try {
            //ClientUtil.SetCertification();// 設置證書
            transport.call(soapAction, envelope);            
            SoapObject sb=(SoapObject)envelope.bodyIn;
            String ss= sb.getProperty(0).toString();
            InputStream inputStream=new ByteArrayInputStream(ss.getBytes());
            return DomWait.readXml(inputStream);            
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (XmlPullParserException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (Exception ex) {
            ex.printStackTrace();
        }
        return null;
    }
    
    public static List<?> queryProcXml(String procName,Vector<String> paraNames,Vector<String> paraValues){
        String methodName = "queryProcXml1";
        String soapAction = "http://tempuri.org/"+methodName;
        
        // 創建webservice鏈接對象
        HttpTransportSE transport = new HttpTransportSE(url);
//        transport.debug = false;// 是不是調試模式
        transport.debug = true;// 是不是調試模式
        // 設置鏈接參數
        SoapObject soapObject = new SoapObject(nameSpace, methodName);
                
        soapObject.addProperty("procName", "AFI02_HOME_GET_WAITING");        
        soapObject.addProperty("ret", 0);
        
        // 設置返回參數
        SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
                SoapEnvelope.VER11);// soap協議版本必須用SoapEnvelope.VER11(Soap V1.1)
        envelope.dotNet = true;// 注意:這個屬性是對dotnetwebservice協議的支持,若是dotnet的webservice
                                // 不指定rpc方式則用true不然要用false
        envelope.bodyOut = soapObject;//千萬注意!!
        
        envelope.setOutputSoapObject(soapObject);// 設置請求參數        
        try {
            //ClientUtil.SetCertification();// 設置證書
            transport.call(soapAction, envelope);            
            SoapObject sb=(SoapObject)envelope.bodyIn;
            String ss= sb.getProperty(0).toString();
            InputStream inputStream=new ByteArrayInputStream(ss.getBytes());
            return DomWait.readXml(inputStream);            
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (XmlPullParserException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (Exception ex) {
            ex.printStackTrace();
        }
        return null;
    }

很腦殘的解析 node

public static List<WaitModel> readXml(InputStream inStream) throws Exceptionweb

{
        List<WaitModel> waitModels=new ArrayList<WaitModel>();
        //實例化一個文檔構建器工廠
        DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
        //經過文檔構建器工廠獲取一個文檔構建器
        DocumentBuilder builder = factory.newDocumentBuilder();
        //經過文檔經過文檔構建器構建一個文檔實例
        Document document = builder.parse(inStream);
        Element root = document.getDocumentElement();
        NodeList nodes = root.getElementsByTagName("Table");
        for(int i = 0 ;i < nodes.getLength();i++)
        {
            Element personElement = (Element)nodes.item(i);
            WaitModel waitModel =new WaitModel();
//            waitModel.setId(Integer.valueOf(personElement.getAttribute("id")));
            NodeList childNodes = personElement.getChildNodes();
            for(int j = 0;j<childNodes.getLength();j++)
            {
                Node childNode = (Node)childNodes.item(j);
                if (childNode.getNodeType()==Node.ELEMENT_NODE)
                {
                    Element childElement = (Element)childNode;
                    if ("PLAN_DATE".equals(childElement.getNodeName()))
                    {
                        waitModel.setPLAN_DATE(childElement.getFirstChild().getNodeValue());
                    }
                    else if ("CORPORATION_NAME_ABB".equals(childElement.getNodeName())) {
                        waitModel.setCORPORATION_NAME_ABB(childElement.getFirstChild().getNodeValue());
                    }
                    else if ("ASSIGN_STATUS".equals(childElement.getNodeName())) {
                        waitModel.setASSIGN_STATUS(childElement.getFirstChild().getNodeValue());
                    }
                    else if ("WORK_ASSIGN_NO".equals(childElement.getNodeName())) {
                        waitModel.setWORK_ASSIGN_NO(childElement.getFirstChild().getNodeValue());
                    }                    
                }
            }
            waitModels.add(waitModel);
        }
        return waitModels;
    }
相關文章
相關標籤/搜索