0

我们在制定对仅使用 XML 协议的远程 API 的请求时遇到问题。我们使用 Apache CXF 项目将 WSDL 文件解析为可轻松导入到我们项目中的类型(.java 文件)。在 CXF 上使用默认参数 none。

我们不确定如何让 KSOAP2 根据接收到的类型来格式化 XML。任何帮助是极大的赞赏。

凯文

public class SOAPRequestTest {

    private static final String NAMESPACE = "http://schemas.xmlsoap.org/soap/envelope/"; 
    private static final String SERVER_HOST = "https://xx.xx.xx.xx/services/LoginService";
    private static final String SERVER_METHOD = "urn:LoginService";

    public void execute() {
        Logger.d("--> Hello");

        new Thread(new Runnable() {
            @Override
            public void run() {
                SoapObject request = new SoapObject(NAMESPACE, SERVER_METHOD);
                GetSecurityInfo getSecurityInfo = new GetSecurityInfo();

                SecurityLogin securityLogin = new SecurityLogin();
                securityLogin.setUserId("testUser");
                securityLogin.setPassword("password");
                securityLogin.setType("consumer");
                securityLogin.setIP("128.2.20.181");
                securityLogin.setLocale("en_US");

                getSecurityInfo.setUser(securityLogin);

                request.addAttribute("user", getSecurityInfo);

                SoapSerializationEnvelope soapSerializationEnvelope = new SoapSerializationEnvelope(1);
                soapSerializationEnvelope.addTemplate(request);
                soapSerializationEnvelope.addMapping("http://xx.xxx.xxx.xxx", "user", GetSecurityInfo.class);

                HttpTransportSE httpTransportSE = new HttpTransportSE(SERVER_HOST);

                httpTransportSE.debug = true;

                try {
                    httpTransportSE.call("getSecurityInfo", soapSerializationEnvelope);

                    Logger.d(httpTransportSE.requestDump);

                    SoapObject soapObject = (SoapObject) soapSerializationEnvelope.getResponse();
                } catch (Exception e) {
                    e.printStackTrace();
                }

            }
        }).start();
    }
}
4

1 回答 1

0

这可能会有所帮助,您可以通过以下方式解析 xml

public ArrayList<OrderBills> getOrderBills(SoapObject result)
    {       
        ArrayList<OrderBills> list=new ArrayList<OrderBills>();

        for(int i=0;i<result.getPropertyCount();i++)
        {   
            OrderBills orderBill=new OrderBills();

            orderBill.setOrderId(Integer.parseInt(((SoapObject)result.getProperty(i)).getProperty(0).toString()));  
            orderBill.setTableNo(((SoapObject)result.getProperty(i)).getProperty(1).toString());
            orderBill.setBillStatus(((SoapObject)result.getProperty(i)).getProperty(2).toString());
            orderBill.setDate(((SoapObject)result.getProperty(i)).getProperty(3).toString());
            orderBill.setTime(((SoapObject)result.getProperty(i)).getProperty(4).toString());

            list.add(orderBill);
        }
        return list;

    }
于 2012-12-31T18:42:49.417 回答