簡體   English   中英

將Web服務響應的形式更改為Java中的數組

[英]Change form of webservice response to array in java

我開發了一個android應用程序,並向Webservice方法發送了一個類對象,我應該以數組作為響應,但它返回anyType {}。

這是我的代碼的一部分。

            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();
                }

我發現除了此代碼以外的其他一些代碼,但它們都不起作用。 有人知道我該怎么辦嗎?

謝謝。

注意:這是我的課程,我想您將按照您在課程中的要求來幫助您。2。相應地替換此變量。3.呼叫方法:在主要類別中使用getDistrictDetials ...這將在CONSOL Windows中打印輸出

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;
    }

}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM