zoukankan      html  css  js  c++  java
  • Android 调用webservice并解析

    这是调用webService的具体方法

    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;
        }

    很脑残的解析 

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

        {
            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;
        }

    转:http://chen249045216.iteye.com/blog/1121586

  • 相关阅读:
    出现Invalid input of type: 'CacheKey'. Convert to a byte, string or number first
    如果错误发生在某个封装号的模块中,那请查看数据库里面的数据是不是哪里出现问题
    发现匿名用户问题
    关于序列化器中class Meta中属性说明
    序列化和反序列化
    前端出现has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource
    出现bad ruqest,查找原因思路
    注册验证出现错误Define UserView.model, UserView.queryset, or override UserView.get_queryset()
    跨域问题
    celery异步使用和启动方法
  • 原文地址:https://www.cnblogs.com/gzggyy/p/3142404.html
Copyright © 2011-2022 走看看