publicStringSelectT(){
//命名空间
String address ="https://ping.xn--fiqs8s/";
//方法名称
String stuName ="Addition";
//服务地址
String logn ="https://ping.中国/ping/";
//方法地址
String stulog ="https://ping.中国/ping/WebMySQL.asmx?op=Addition";
//这里是调用地址,一个空间,一个方法名
SoapObject soap =newSoapObject(address,stuName);
//这个方法的参数
soap.addProperty("num1",123);
soap.addProperty("num2",123);
//指定版本webserver服务的版本
SoapSerializationEnvelope envelope =newSoapSerializationEnvelope(SoapEnvelope.VER12);
envelope.bodyOut= soap;
envelope.dotNet=true;//支持.net开发的server服务
newMarshalBase64().register(envelope);//指定编码
HttpTransportSE httpTr =newHttpTransportSE(logn);//使用Http服务链接
//HttpsTransportSE httpTr = new HttpsTransportSE("https://ping.中国",443,"/ping",6000);
httpTr.debug=true;
//保持长连接。
//如果是false就仅支持一次链接。
//true支持多次连接。
System.setProperty("http.keepAlive","false");
try{
//调用获取数据
httpTr.call(stulog,envelope);
}catch(XmlPullParserException e) {
e.printStackTrace();
}catch(IOException e) {
e.printStackTrace();
}
//接受服务器返回的值
SoapObject result = (SoapObject) envelope.bodyIn;
String res = result.getProperty(0).toString();
returnres;
}
上面是连接的方法
class QueryAddressTask extends AsyncTask<> {
@Override
protected String doInBackground(String... strings) {
String res = SelectT();
returnres;
}
@Override
//此方法可以在主线程改变UI
protected voidonPostExecute(String result) {
Toast.makeText(MainActivity.this,result,Toast.LENGTH_LONG).show();
}
}
这是创建一个线程
newQueryAddressTask().execute();//开启线程
开启创建的线程
网友评论