我已经有两天时间试图解决这个问题,但是我无法弄清楚发生了什么:
我在本地服务器中创建了一个Web服务器,Web服务在浏览器Web上工作正常,如果我在eclipse上从WSDL菜单调用也工作正常。
问题是从Android APP连接到WebService,当我调用方法androidHttpTransport.call 时,它会抛出一个SocketTimeoutException:
java.net.SocketTimeoutException: Connection timed out
问题是,我第一次创建一个示例Web服务时,它正确连接到我的服务器,但在创建一个新项目和另一个服务器的新实例(我删除了第一个)之后,相同的代码开始抛出异常
我一直在尝试重复所有步骤,但即使使用示例代码,它仍然会抛出异常。
这是源代码:
String namespace = "http://ws.example.iio";
String soap_action = "http://ws.example.iio/getStatus";
String method = "getStatus";
String url = "http://10.0.0.22:8081/Project/services/WebService?wsdl";
try{
//Initialize soap request + add parameters
SoapObject request = new SoapObject(namespace, method);
//Declare the version of the SOAP request
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.setOutputSoapObject(request);
envelope.dotNet = false;
try {
HttpTransportSE androidHttpTransport = new HttpTransportSE(url);
androidHttpTransport.debug = true;
//this is the actual part that will call the webservice
androidHttpTransport.call(soap_action, envelope);
// Get the SoapResult from the envelope body.
SoapObject result = (SoapObject)envelope.bodyIn;
if(result != null)
{
//Get the first property and change the label text
String text = result.getProperty(0).toString();
text = "" + text;
}
else
{
Toast.makeText(getApplicationContext(), "No Response",Toast.LENGTH_LONG).show();
}
} catch (Exception e) {
e.printStackTrace();
}
} catch (Exception e) {
e.printStackTrace();
}