网络服务的结果?

时间:2013-08-04 06:30:41

标签: android web-services soap

我用SOAP函数编写了一个代码来获取Web服务,问题是响应不是一个xml字符串,我需要知道的是,我的android代码SOAP函数的错误?还是来自网络服务? 为什么结果是liske这个

 public String SOAP_ACTION2 = "http://tempuri.org/GetDataTable";

    public String OPERATION_NAME2 = "GetDataTable";

    public String SOAP_ADDRESS2 = "http://192.168.0.15/EServicedesk/DesktopModules/EServiceDesk.Website/ESDWebService/Auth.asmx?WSDL";
Object response;
String XMLData = null;
    SoapSerializationEnvelope envelope;
    SoapRequestTask2 task;

 @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        task = new SoapRequestTask2();
        try { 
            XMLData = task.execute().get();
            Log.i("task ", XMLData);
        } catch (InterruptedException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (ExecutionException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

}

private class SoapRequestTask2 extends AsyncTask<Void, Void, String> {
        // runs on ui thread.
        private String data;

        protected void onPreExecute() {

        }

        // runs in the background thread. do not update ui from here
        protected String doInBackground(Void... params) {
            SoapObject request = new SoapObject(WSDL_TARGET_NAMESPACE,
                    OPERATION_NAME2);
            PropertyInfo pi = new PropertyInfo();
            pi.setName("UserID");
            pi.setValue(193);
            pi.setType(Integer.class);
            request.addProperty(pi);


            envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
            envelope.dotNet = true;

            envelope.setOutputSoapObject(request);

            HttpTransportSE httpTransport = new HttpTransportSE(SOAP_ADDRESS2);

            response = null;
            try {
                // httpTransport.debug=true;
                httpTransport.call(SOAP_ACTION2, envelope);
                // String ss = httpTransport.requestDump;
                response = envelope.getResponse();

                data = response.toString();
            //  Log.i("respons", envelope.getResponse().toString());
            } catch (Exception exception) {
                response = exception.toString();
                XMLData = response.toString();
            }

            return data;
        }

结果如下: 任务2:anyType {schema = anyType {element = anyType {complexType = anyType {choice = anyType {element = anyType {complexType = anyType {sequence = anyType {element = anyType {};元素= anyType的{}; }; }; }; }; }; }; };的DiffGram = anyType的{DocumentElement = anyType的{TargetTable = anyType的{RequestHotList = MyRequests;计数= 927; }; TargetTable = anyType的{RequestHotList = MyAssignedRequests;计数= 603; }; TargetTable = anyType的{RequestHotList = MyServiceDeskRequests;计数= 969; }; TargetTable = anyType的{RequestHotList = MyWorkGroupRequests;计数= 770; }; TargetTable = anyType的{RequestHotList = MyApproval;计数= 82; }; }; }; }

1 个答案:

答案 0 :(得分:0)

你可以做这样的事情

Web服务返回对象数组

您可以通过转到相关节点获取每个对象的每个值的值,然后使用getProperty()方法获取所需对象的值,如下所示。 //旧的Web服务。

public void  getLocation()
{
    OPERATION_NAME = "GetLd";   
    SOAP_ACTION = Constants.strNAMESPACE+""+OPERATION_NAME;     
        REQUST_ID=3;
        final Responce responce=new Responce();
        Thread thread=new Thread(new Runnable() 
        {

            SoapObject response;                
            @Override
            public void run() 
            {
                try
                {
                SoapObject request=new SoapObject(Constants.strNAMESPACE, OPERATION_NAME);
                SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
                envelope.setOutputSoapObject(request);
                HttpTransportSE ht = new HttpTransportSE(Constants.strWEB_SERVICE_URL);
                ht.call(SOAP_ACTION, envelope);
                response = (SoapObject)envelope.bodyIn;
                if(response!=null)
                {
                     SoapObject str = null;
                        for(int i=0;i<response.getPropertyCount();i++)
                                str=(SoapObject) response.getProperty(i);       


                        SoapObject str1 = (SoapObject) str.getProperty(0);

                        SoapObject str2 = null;
                        ArrayList<Location> arrData=new ArrayList<Location>();
                        for(int j=0;j<str1.getPropertyCount();j++)
                        {                       
                            str2 = (SoapObject) str1.getProperty(j);
                            Location location=new Location();
                            if(str2!=null)
                            {   
                                responce.Result_Type=Constants.DataPresent;

                                if(isValidProperty(str2, "LocationName"))
                                {
                                    location.setName(str2.getProperty("LocationName").toString());
                                }
                                if(isValidProperty(str2, "LocationId"))
                                {
                                    location.setId(Integer.parseInt(str2.getProperty("LocationId").toString()));
                                }   
                                arrData.add(location);
                            }
                            else
                            {
                                responce.Result_Type=Constants.NoDataPresent;
                            }                               
                        }
                        responce.ResponceData=arrData;
                        Log.d("Location", "------------------------");
                        for(int i=0;i<arrData.size();i++)
                            Log.d("Tag", arrData.get(i).toString());
                      }
                }          
                catch (Exception e) 
                {       
                    e.printStackTrace();
                    responce.Result_Type=Constants.Error;
                }
                finally
                {
                    Message message=new Message();
                    message.what=REQUST_ID;
                    message.arg1=responce.Result_Type;
                    message.obj=responce;               
                    handler.sendMessage(message);
                }       
            }

        });
        thread.start();
}







 boolean isValidProperty(SoapObject soapObject,String PropertyName)
    {
        if(soapObject!=null)
        {
            if(soapObject.hasProperty(PropertyName))
            {
                if(!soapObject.getProperty(PropertyName).toString().equalsIgnoreCase("")&&!soapObject.getProperty(PropertyName).toString().equalsIgnoreCase("anyType{}"))
                    return true;
            else
                return false;
            }
            return false;

        }
        else
            return false;

    }