简体   繁体   中英

Change form of webservice response to array in java

I develop an android application and i send a class object to a webservice method and i supposed to take an array as response but it returns anyType{}.

Here is a part of my code.

            Customer C = new Customer();
            C.setProperty(0,"30000001");

            PropertyInfo pi =new PropertyInfo();
            pi.setName("customer");        
            pi.setValue(C);            
            pi.setType(C.getClass());  
            request.addProperty(pi);   



            try{
            androidHttpTransport.call(SOAP_ACTION1, envelope);

            SoapObject response = (SoapObject) envelope.bodyIn;

                String[] denemeList;

                denemeList = new String[response.getPropertyCount()];

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

                   denemeList[i] = response.getPropertyAsString(i).toString();
                   Log.d("This is the response",denemeList[i]);

                } 
                }catch (Exception e) {
                     TextView01.setText("EXCEPTION");
                     e.printStackTrace();
                }

I find some other codes except from this one but none of them work. Anyone know what should i do?

Thanks.

NOTE : HERE IS MY CLASS , I THINK IT WILL HELP YOU JUST POST tHIS CLASS AS IT IS IN UR PROJECT 2. REPLACE THE VARIABLE ACCORDINGLY 3. CALL METHOD : getDistrictDetials IN SUPPOSE MAIN CLASS...THIS WILL PRINT THE OUTPUT IN CONSOL WINDOW

public class WebServiceCaller {

    private final String NAMESPACE = "http://tempuri.org/";
    private final String URL = "http://www.MYSERVICE/Service.asmx";
    private final String SOAP_ACTION = "http://tempuri.org/RASHTRWADI_State";
    private final String METHOD_NAME = "RASHTRWADI_State";



    public boolean getDistrictDetials() {
        boolean result = false;
        SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
        PropertyInfo propInfo1 = new PropertyInfo();
        propInfo1.setName("State_Code");
        propInfo1.setValue(1);
        propInfo1.setType(int.class);
        request.addProperty(propInfo1);
        SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
                SoapEnvelope.VER11);
        envelope.dotNet = true; // put this only if the web service is .NET one
        envelope.setOutputSoapObject(request);
        HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
        try {
            androidHttpTransport.call(SOAP_ACTION, envelope);
            // SoapPrimitive response = (SoapPrimitive)envelope.getResponse();
            Object response1 = envelope.getResponse();
            SoapObject response = (SoapObject) response1;

            Log.i("myApp", response1.toString());

        } catch (Exception e) {
            e.printStackTrace();
        }
        return result;
    }

}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM