繁体   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