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

时间:2012-05-31 05:53:19

标签: android web-services

我找到了一个用于从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 result =(SoapObject)envelope.getResponse();

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

0 个答案:

没有答案