需要在android中显示从web服务asmx中恢复的值

时间:2016-04-02 06:53:50

标签: android web-services asmx

我需要在android中显示来自web服务asmx的已检索数据。

private class AsyncCallWS extends AsyncTask<Void, Void, Void> {
    public boolean isOnline()
    {

        ConnectivityManager localConnectivityManager = (ConnectivityManager)getSystemService("connectivity");
        NetworkInfo localNetworkInfo = localConnectivityManager.getActiveNetworkInfo();
        return (localNetworkInfo != null) && (localNetworkInfo.isConnectedOrConnecting()) && (localConnectivityManager.getActiveNetworkInfo().isAvailable()) && (localConnectivityManager.getActiveNetworkInfo().isConnected());
    }

    @Override
    protected void onPreExecute() {
        Log.i(TAG, "onPreExecute");
    }

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

        Log.i(TAG, "doInBackground");

        String NAMESPACE = "http://tempuri.org/";
        String URL = "http://example.com/example/GroupMessage/GroupMessage.asmx";

        String METHOD_NAME = "GroupList";

        String SOAP_ACTION = "http://tempuri.org/GroupList";

        try {
            SoapObject Request = new SoapObject(NAMESPACE, METHOD_NAME);
            Request.addProperty("PortalId","0");
            Request.addProperty("ModuleId", "1884");

            SoapSerializationEnvelope soapEnvelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
            soapEnvelope.dotNet = true;
            soapEnvelope.setOutputSoapObject(Request);

            HttpTransportSE transport = new HttpTransportSE(URL);

            transport.call(SOAP_ACTION, soapEnvelope);               

            resultString = (SoapObject)soapEnvelope.getResponse();      

            Log.i(TAG, "Result Login: " + resultString);

        } catch (Exception ex) {
            Log.e(TAG, "Error: " + ex.getMessage());
        }
        return null;
    }

    @Override
    protected void onPostExecute(Void result) {

        Log.i(TAG, "onPostExecute");

        mInformationTextView = (TextView) findViewById(R.id.informationTextView);

        mInformationTextView.setText(resultString.toString());

        /* Datas from web service */

        SoapObject request2 = (SoapObject)resultString.getProperty(0);

         for(int i=0; i<request2.getPropertyCount(); i++) {


             **///// code to display datas //////////**

         }

        Toast.makeText(MainActivity.this, "Response" + resultString.toString(), Toast.LENGTH_LONG).show();
    }

现在我得到这样的回应--- anyType的{SalGM_GroupInfo = anyType的{PortalId = 0;的moduleId = 1884;的GroupId = 1;组名=测试1; }; SalGM_GroupInfo = anyType的{PortalId = 0;的moduleId = 1884;的GroupId = 2;组名= Test2的; }; SalGM_GroupInfo = anyType的{PortalId = 0;的moduleId = 1884;的GroupId = 3;组名= Test3的; }; SalGM_GroupInfo = anyType的{PortalId = 0;的moduleId = 1884;的GroupId = 4;组名= TEST4; }; }

我需要使用动态文本视图

在android中显示输出

PortalId = 0
ModuleId = 1884
的GroupId = 1
组名= Test1的
PortalId = 0
的moduleId = 1884年
的GroupId = 2
组名= Test2的
PortalId = 0
ModuleId = 1884
的GroupId = 3
组名= Test3的
PortalId = 0
的moduleId = 1884年
的GroupId = 4
组名= TEST4

任何建议请帮助,

感谢。

2 个答案:

答案 0 :(得分:0)

我想你想在收到回复后显示有关活动的数据,如果我是对的,你必须遵循一些步骤,否则忽略这个答案&amp;简要地告诉我。

请参阅此链接http://www.mysamplecode.com/2012/07/android-populate-listview-from-json.html

要实现这一目标,您必须创建CustomAdapter类&amp;使用ListView获取多个数据。按照上面的链接,他如何做同样的事情。

答案 1 :(得分:0)

您必须将String响应转换为JSONObject响应,并应解析为textviews.reffer以下链接。 http://andygeeks.blogspot.in/2014/04/parse-json-format-data-from-soap-web.html