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

 

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值