关于sql server:如何从android调用ksoap web service

how to Call ksoap web service from android

我想在 android studio 中使用 ksoap 库。
但我对此还不够承认。
(我总是使用 Volley lib 从 php api 发送/接收,它工作正常。)

网址:
http://sms141.ir/sms141_webservice.asmx

我的功能:

1
public object[] CheckUsers(string number , string user  , string pass)

SOAP_ACTIONNAMESPACE 变量是否正确?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
private static final String SOAP_ACTION ="http://sms141.ir/CheckUsers";
private static final String METHOD_NAME ="CheckUsers";
private static final String NAMESPACE ="http://sms141.ir";
private static final String URL ="http://sms141.ir/sms141_webservice.asmx";


@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.sms_login);

    myAsyncTask myRequest = new myAsyncTask();
    myRequest.execute();

}


private class myAsyncTask extends AsyncTask<Void, Void, Void> {


    @Override
    protected void onPostExecute(Void result) {
        super.onPostExecute(result);
       // tv.setText(response);
    }

    @Override
    protected void onPreExecute() {
        super.onPreExecute();
    }

    @Override
    protected Void doInBackground(Void... arg0) {

        SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
        request.addProperty("number","value");
        request.addProperty("user","value");
        request.addProperty("pass","value");

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

        HttpTransportSE httpTransport = new HttpTransportSE(URL);

        httpTransport.debug = true;
        try {
            httpTransport.call(SOAP_ACTION, envelope);
        }catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (XmlPullParserException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } //send request
        SoapObject result = null;
        try {
            result = (SoapObject)envelope.getResponse();
        } catch (SoapFault e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

        Log.d("App",""+result.getProperty(1).toString());
        String response = result.getProperty(1).toString();


        Log.e("result","0"+response);


        return null;
    }
}

我收到这些错误:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
> 06-17 18:32:02.751  11495-11515/com.almas.mehr.sms E/AndroidRuntime?1?
> FATAL EXCEPTION: AsyncTask #1
>     java.lang.RuntimeException: An error occured while executing doInBackground()
>             at android.os.AsyncTask$3.done(AsyncTask.java:299)
>             at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:352)
>             at java.util.concurrent.FutureTask.setException(FutureTask.java:219)
>             at java.util.concurrent.FutureTask.run(FutureTask.java:239)
>             at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:230)
>             at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080)
>             at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573)
>             at java.lang.Thread.run(Thread.java:856)
>      Caused by: java.lang.NullPointerException
>             at com.almas.mehr.sms.Login$myAsyncTask.doInBackground(Login.java:211)
>             at com.almas.mehr.sms.Login$myAsyncTask.doInBackground(Login.java:166)
>             at android.os.AsyncTask$2.call(AsyncTask.java:287)
>             at java.util.concurrent.FutureTask.run(FutureTask.java:234)
> ????????????at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:230)
> ????????????at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080)
> ????????????at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573)
> ????????????at java.lang.Thread.run(Thread.java:856)

根据我对您的问题的理解,您只需要知道如何将 KSOAP2 库与 android 一起使用来与服务器进行通信。

这是一个链接,您将通过该链接获得实现

http://karanbalkar.com/2014/03/tutorial-78-using-ksoap2-in-android/

如何在android中使用KSoap 2