Android之SOAP协议与WebService服务器交互,解决超时的问题


网络搜索大部分不能实际解决问题。特意将解决方法写下。
创建MyAndroidHttpTransport 类 ,

package com.example.omhandroid.lib;

import org.ksoap2.transport.HttpTransportSE;
import org.ksoap2.transport.ServiceConnection;

import java.io.IOException;
import java.net.SocketException;

public class MyAndroidHttpTransport extends HttpTransportSE {

private int timeout = 600000; //默认超时时间为60s*10
private int readTimeout = 600000; //默认超时时间为60s*10
public MyAndroidHttpTransport(String url) {
super(url);
}

public MyAndroidHttpTransport(String url, int timeout) {
super(url);
this.timeout = timeout;
}
public ServiceConnection getServiceConnection() throws IOException {
return new org.ksoap2.transport.ServiceConnectionSE(this.proxy, this.url, this.timeout, this.readTimeout);
}
}



调用如下:

// 生成调用WebService方法调用的soap信息,并且指定Soap版本
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
// 是否调用DotNet开发的WebService
envelope.dotNet = true;

envelope.setOutputSoapObject(request);

MyAndroidHttpTransport httpTransport = new MyAndroidHttpTransport(SOAP_ADDRESS);

httpTransport.debug = true;
try {
httpTransport.call(WSDL_TARGET_NAMESPACE + OPERATION_NAME, envelope);
Object response = envelope.getResponse();
return response.toString();
} catch (Exception exception) {
exception.printStackTrace();
return "";
}

实测有效,可以放心使用

Android之SOAP协议与WebService服务器交互,解决超时的问题

上一篇:appium +夜神模拟器


下一篇:Android 内存