
新建两个工具类ConnectWeb.java 和 ConnectMethod.java 进行对服务器进行数据交互
ConnectWeb.java代码如下:
public class ConnectWeb { private static final String nameSpace = "http://gdhs.com/"; private String ip = null; private int timeout = 3000; private int numbercs = 0; SoapObject rpc = null; String methodname = null; public ConnectWeb(String methodname,String ip,int timeout,int numbercs){ this.methodname = methodname; this.ip = " http://" + ip + "/" + "CYService" + ".asmx"; this.timeout = timeout; this.numbercs = numbercs; rpc = new SoapObject(nameSpace,this.methodname); } public voID addProperty(String name,String value){ rpc.addProperty(name,value); } public SoapObject connectToService()throws Exception{ try { httpTransportSE hts = new httpTransportSE(ip,timeout); hts.deBUG = true; SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11); envelope.bodyOut = rpc; envelope.dotNet = true; envelope.setoutputSoapObject(rpc); hts.call(nameSpace+this.methodname,envelope); SoapObject result = (SoapObject)envelope.bodyIn; Log.i("AAA","ConnectWeb从数据库拿到的数据result==========>"+result); return result; }catch (Exception e){ Log.i("AAA","ConnectWeb从数据库拿数据出错==========>"+e.getMessage()); return null; } }}
ConnectMethod.java 代码如下:
public class ConnectMethod { public static String connectWebService(String ip,String methodname,String jkxlh,String jkID,String xmlDoc,String ResultGs,int timeout,int cscs){ try { ConnectWeb web = new ConnectWeb(methodname,ip,timeout,cscs); web.addProperty("xtlb","01"); web.addProperty("jkxlh",jkxlh); web.addProperty("jkID",jkID); web.addProperty("xmlDoc",xmlDoc); SoapObject result = web.connectToService(); String dataOne = result.getProperty(ResultGs).toString(); String dataTwo = URLDecoder.decode(dataOne,"UTF-8"); return dataTwo; } catch (Exception e) { e.printstacktrace(); return null; } }}
调服务器接口获取数据:
String result = ConnectMethod.connectWebService(ip,methodname,jkxlh,"01C07",xmlDoc,queryResult,timeoutFive,timeoutThree);
返回数据由服务器方法决定。
总结以上是内存溢出为你收集整理的Android-----使用SoapObject获取服务器数据全部内容,希望文章能够帮你解决Android-----使用SoapObject获取服务器数据所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)