1

我使用 KSOAP2 从 .net WebService 获取数据来完成我的工作。这是我在代码中的主要部分

private static final String NAMESPACE = "http://tempuri.org/";
private static final String METHOD_NAME = "CountCatalog";
private static final String SOAP_ACTION = NAMESPACE + METHOD_NAME;
private static final String URL = "http://myservice.somee.com/mywebservice.asmx?WSDL";

myAsyncTask 的代码:

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

    @Override
    protected void onPostExecute(Void result) {
        // TODO Auto-generated method stub
        super.onPostExecute(result);
        txtcount.setText(reply);
    }

    @Override
    protected void onPreExecute() {
        // TODO Auto-generated method stub
        super.onPreExecute();
    }

    @Override
    protected Void doInBackground(Void... params) {
        // TODO Auto-generated method stub
        try {
            SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
            SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
            envelope.dotNet = true;
            envelope.setOutputSoapObject(request);

            HttpsTransportSE httpTransport = new HttpsTransportSE(URL, 0, null, 0);

            httpTransport.call(SOAP_ACTION, envelope);
            SoapPrimitive response = (SoapPrimitive) envelope.getResponse();
            reply = response.toString();
            //txtcount.setText(response.toString());
        } catch (IOException | XmlPullParserException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }


        return null;
    }

}

并在函数中使用 AsyncTask:

btncount.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
            doCount();
        }
    });
}
private void doCount(){

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

这是日志错误:

04-20 21:22:38.125: E/AndroidRuntime(277): FATAL EXCEPTION: AsyncTask #1
04-20 21:22:38.125: E/AndroidRuntime(277): java.lang.RuntimeException: An  
04-20 21:22:38.125: E/AndroidRuntime(277):  at java.net.URL.<init>(URL.java:403)
04-20 21:22:38.125: E/AndroidRuntime(277):  at java.net.URL.<init>(URL.java:356)
04-20 21:22:38.125: E/AndroidRuntime(277):  at  org.ksoap2.transport.HttpsServiceConnectionSE.<init>(HttpsServiceConnectionSE.java:51)
    04-20 21:22:38.125: E/AndroidRuntime(277):  at org.ksoap2.transport.HttpsTransportSE.getServiceConnection(HttpsTransportSE.java:47)
04-20 21:22:38.125: E/AndroidRuntime(277):  at org.ksoap2.transport.HttpTransportSE.call(HttpTransportSE.java:124)
04-20 21:22:38.125: E/AndroidRuntime(277):  at org.ksoap2.transport.HttpTransportSE.call(HttpTransportSE.java:95)
04-20 21:22:38.125: E/AndroidRuntime(277):  at com.example.webservice1.MainActivity$myAsyncTask.doInBackground(MainActivity.java:91)
04-20 21:22:38.125: E/AndroidRuntime(277):  at com.example.webservice1.MainActivity$myAsyncTask.doInBackground(MainActivity.java:1)
04-20 21:22:38.125: E/AndroidRuntime(277):  at android.os.AsyncTask$2.call(AsyncTask.java:185)
04-20 21:22:38.125: E/AndroidRuntime(277):  at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)
4

0 回答 0