Two new tools ConnectWeb.java and ConnectMethod.java be the server data exchange
ConnectWeb.java code is as follows:
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 ( " the AAA " , " ConnectWeb get data from a database ========== Result> " + Result); return Result; } the catch (Exception E) { Log.i ( " the AAA " , " ConnectWeb get data from a database error ==========> " + e.getMessage ()); return null ; } } }
ConnectMethod.java code is as follows:
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; } } }
Tune server interface to obtain data:
String result = ConnectMethod.connectWebService(ip , methodName , jkxlh , "01C07", xmlDoc ,queryResult , timeoutFive, timeoutThree);
Method returns the data determined by the server.