0

我找到了一个从 Android 调用 Web 服务的示例代码,如下所示:

import org.ksoap2.SoapEnvelope;
import org.ksoap2.serialization.SoapObject;
import org.ksoap2.serialization.SoapPrimitive;
import org.ksoap2.serialization.SoapSerializationEnvelope;
import org.ksoap2.transport.HttpTransportSE;
//...
try
{
SoapObject request = new SoapObject(NAMESPACE, GET_INTREBARE);

// add paramaters and values
request.addProperty("idTest", idTest);
request.addProperty("idIntrebare", idIntrebare);

SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.dotNet = true;
envelope.setOutputSoapObject(request);

//Web method call
HttpTransportSE androidHttpTransport = new HttpTransportSE(URL_WS);
androidHttpTransport.call(NAMESPACE + GET_INTREBARE, envelope);
//get the response
SoapObject result = (SoapObject) envelope.getResponse();

//the response object can be retrieved by its name: result.getProperty("objectName")
}
catch (Exception e)
{
e.printStackTrace();
}

在上面的代码中,HttpTransportSE用于调用 Web 服务方法。我的疑问是,当我们调用 Web 服务时,可能会有一些延迟来获得响应,具体取决于网络。

在上面的代码中,响应在 Web 服务被调用后立即分配给 SoapObject。

SoapObject 结果 = (SoapObject) 信封.getResponse();

当我们从 Web 服务调用中获得响应时,是否可以触发自定义事件?

4

0 回答 0