我怎样才能使异步任务ksoap2电话吗?能使、任务、电话

2023-09-03 07:50:00 作者:怎安过往

我在Android开发的新手。我试图开发一种将与.NET Web服务连接,以便检索数据的应用程序。我想提出与异步任务ksoap2电话。我怎么称呼它的AsyncTask asyncronus?

我的SOAPCall类

 公共类的SOAPCall {

公共最后静态字符串SOAP_ACTION =htt​​p://www.alpha.net.com/ExecuteEBSCommand;

公共最后静态字符串OPERATION_NAME =ExecuteEBSCommand;

公共最后静态字符串NAMESPACE =htt​​p://www.alpha.net.com;

公共最后静态字符串URL =htt​​p://192.168.2.100/Ebs2Alpha/Service.asmx;





公共字符串连接(字符串命令,字符串CommandParameters)抛出的Throwable,Throwable的{
    串响应=无效;
    SoapObject请求=新SoapObject(命名空间OPERATION_NAME);
    Request.addProperty(strCommand,命令);
    Request.addProperty(strCommandParameters,CommandParameters);



    SoapSerializationEnvelope的SoapEnvelope =新SoapSerializationEnvelope(
            SoapEnvelope.VER11);
    soapEnvelope.dotNet = TRUE;
    soapEnvelope.setOutputSoapObject(请求);
    //需要做互联网电话

    //允许进行调试 - 需要输出的要求

        HttpTransportSE androidHttpTransport =新HttpTransportSE(URL);
        androidHttpTransport.debug = TRUE;
        //这是将调用Web服务的实际组成部分
        androidHttpTransport.call(SOAP_ACTION,的SoapEnvelope);

        //从信封体在SOA presult。
        SoapObject结果=(SoapObject)soapEnvelope.bodyIn;

        响应= result.getProperty(0)的ToString();


    返回响应;
    }
 

}

到目前为止,我正在通过调用主要活动的连接方法与响应

 的SOAPCall CALL1 =新的SOAPCall();

call1.connection(get_clients,%);
 

解决方案

使用AsyncTask的很简单。下面是一个例子。

 公共类MyTask的扩展AsyncTask的<字符串,整数,字符串> {


    @覆盖
    保护字符串doInBackground(字符串... PARAMS){
    串响应=无效;
    SoapObject请求=新SoapObject(命名空间OPERATION_NAME);
    Request.addProperty(strCommand,则params [0]);
    Request.addProperty(strCommandParameters,则params [1]);



    SoapSerializationEnvelope的SoapEnvelope =新SoapSerializationEnvelope(
        SoapEnvelope.VER11);
    soapEnvelope.dotNet = TRUE;
    soapEnvelope.setOutputSoapObject(请求);
    //需要做互联网电话

    //允许进行调试 - 需要输出的要求

    HttpTransportSE androidHttpTransport =新HttpTransportSE(URL);
    androidHttpTransport.debug = TRUE;
    //这是将调用Web服务的实际组成部分
    androidHttpTransport.call(SOAP_ACTION,的SoapEnvelope);

    //从信封体在SOA presult。
    SoapObject结果=(SoapObject)soapEnvelope.bodyIn;

    响应= result.getProperty(0)的ToString();


    返回响应;
}
 
未来科技城这些 黑科技 亮相世界互联网大会 快来看

}

和使用参数调用任务。

  MyTask的MyTask的=新MyTask的();
myTask.execute(新的String [] {命令,CommandParameters});
 

希望这将有助于。

I am a newbie on android development. I am trying to develop an application which will connect with .net webservice in order to retrieve data. I would like to make the ksoap2 call with async task. How I call it asyncronus with asynctask?

My SoapCall class is

public class SoapCall {

public final static String SOAP_ACTION = "http://www.alpha.net.com/ExecuteEBSCommand";

public final static String OPERATION_NAME = "ExecuteEBSCommand";

public final static String NAMESPACE = "http://www.alpha.net.com";

public final static String URL = "http://192.168.2.100/Ebs2Alpha/Service.asmx";





public String connection(String Command, String CommandParameters) throws Throwable, Throwable {
    String response = null;
    SoapObject Request = new SoapObject(NAMESPACE, OPERATION_NAME);
    Request.addProperty("strCommand", Command);
    Request.addProperty("strCommandParameters", CommandParameters);



    SoapSerializationEnvelope soapEnvelope = new SoapSerializationEnvelope(
            SoapEnvelope.VER11);
    soapEnvelope.dotNet = true;
    soapEnvelope.setOutputSoapObject(Request);
    // Needed to make the internet call

    // Allow for debugging - needed to output the request

        HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
        androidHttpTransport.debug = true;
        // this is the actual part that will call the webservice
        androidHttpTransport.call(SOAP_ACTION, soapEnvelope);

        // Get the SoapResult from the envelope body.
        SoapObject result = (SoapObject) soapEnvelope.bodyIn;

        response = result.getProperty(0).toString();


    return response;
    }

}

So far I am getting the response by calling the connection method in main activity with

SoapCall  call1= new SoapCall();

call1.connection("get_clients", "%");

解决方案

Using asynctask is straightforward. Here is an example.

 public class MyTask extends AsyncTask<String, Integer, String>{


    @Override
    protected String doInBackground(String... params) {
    String response = null;
    SoapObject Request = new SoapObject(NAMESPACE, OPERATION_NAME);
    Request.addProperty("strCommand", params[0]);
    Request.addProperty("strCommandParameters", params[1]);



    SoapSerializationEnvelope soapEnvelope = new SoapSerializationEnvelope(
        SoapEnvelope.VER11);
    soapEnvelope.dotNet = true;
    soapEnvelope.setOutputSoapObject(Request);
    // Needed to make the internet call

    // Allow for debugging - needed to output the request

    HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
    androidHttpTransport.debug = true;
    // this is the actual part that will call the webservice
    androidHttpTransport.call(SOAP_ACTION, soapEnvelope);

    // Get the SoapResult from the envelope body.
    SoapObject result = (SoapObject) soapEnvelope.bodyIn;

    response = result.getProperty(0).toString();


    return response;
}

}

And the call to the task with parameters.

MyTask myTask = new MyTask();
myTask.execute(new String[] {Command, CommandParameters});

Hope it will help.