我正在尝试使用此代码调用Web服务
public final String SOAP_ACTION = "http://tempuri.org/IServices/Login";
public final String OPERATION_NAME = "Login";
public final String WSDL_TARGET_NAMESPACE = "http://tempuri.org/";
public final String SOAP_ADDRESS = "http://localhost:9198/Services.svc/soap";
public final int TIMEOUT = 3000000;
SoapObject request = new SoapObject(WSDL_TARGET_NAMESPACE, OPERATION_NAME);
PropertyInfo pi = new PropertyInfo();
pi.setName("emailConn");
pi.setValue(emailConn);
pi.setType(String.class);
request.addProperty(pi);
pi = new PropertyInfo();
pi.setName("passwordConn");
pi.setValue(passwordConn);
pi.setType(String.class);
request.addProperty(pi);
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
SoapEnvelope.VER11);
envelope.dotNet = true;
envelope.setOutputSoapObject(request);
HttpTransportSE httpTransport = new HttpTransportSE(SOAP_ADDRESS, TIMEOUT);
String response;
try {
httpTransport.call(SOAP_ACTION, envelope);
response = (String) envelope.getResponse();
} catch (Exception exception) {
response = exception.toString();
}
String res = response.toString();
但在捕获时给出异常 res = java.net.SocketTimeOutException
如何解决这个问题请解释
如果还没有,则需要在AndroidManifest.xml
中添加以下行:
<uses-permission android:name="android.permission.INTERNET"/>
这就是解决我SocketTimeOutException
的问题。