`
yidongkaifa
  • 浏览: 4059802 次
文章分类
社区版块
存档分类
最新评论

Android平台调用.NET WebService详解

 
阅读更多

Android调用.NET WebService 的注意事项!

网上有些资料说在需要传入多个参数时,只要多个参数的顺序与WSDL中参数出现的顺序一致即可,名称并不需要和WSDL中的一致,但实际测试发现,大多数情况下并不可行!)

// 调用的方法
		String methodName = "GetGoodsSet_Android";
		// 创建HttpTransportSE传输对象
		HttpTransportSE ht = new HttpTransportSE("http://192.168.1.115/Android_WebService/WebService1.asmx");
		ht.debug = true;
		// 实例化SoapObject对象
		SoapObject soapObject = new SoapObject(SERVICE_NS, methodName);
		// 添加一个请求参数
		soapObject.addProperty("queryPara", queryPara);
		soapObject.addProperty("pagesze", PageSize);
		// 使用SOAP1.1协议创建Envelop对象
		SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
			SoapEnvelope.VER11);
		envelope.bodyOut = soapObject;
		// 设置与.Net提供的Web Service保持较好的兼容性
		envelope.dotNet = true;
		try
		{
			// 调用Web Service
			ht.call("http://tempuri.org/GetGoodsSet_Android", envelope);
			//Log.println(priority, tag, msg)
			if (envelope.getResponse() != null)
			{
				// 获取服务器响应返回的SOAP消息
				SoapObject result = (SoapObject)envelope.bodyIn;
				  //SoapPrimitive  result_P = (SoapPrimitive) envelope.getResponse();   

				  
				//DialogUtil.showDialog(Main,WebServiceUtil.getCityListByProvince(), false);
				System.out.println(result.getAttributeCount());
//				SoapObject detail = (SoapObject) result.getProperty(methodName
//					+ "Result");
				// 解析服务器响应的SOAP消息。
				//return parseProvinceOrCity(detail);
				//SoapObject chileds =(SoapObject) result.getProperty(0);	
				//SoapObject chiled_s =(SoapObject) chileds.getProperty(1);	
				//JSONObject js_obj=new JSONObject(envelope.getResponse().toString());
				
				return envelope.getResponse().toString();
			}else{
				return "Null";
			}
		}
		catch (IOException e)
		{
			e.printStackTrace();
			return e.getLocalizedMessage();
		}
		catch (XmlPullParserException e)
		{
			
			e.printStackTrace();
			return e.getLocalizedMessage();
		}


分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics