簡體   English   中英

如何從SOAP Web服務獲取鍵和值?

[英]How to get key and value from SOAP Webservice?

我嘗試使用ksoap2-android-assembly-3.3.0-jar-with-dependencies.jar

我嘗試獲取鍵和值,但是我不能..我嘗試了此代碼。

    SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
                SoapEnvelope.VER11);
        envelope.setOutputSoapObject(request);

        envelope.dotNet = true;

        HttpTransportSE androidHttpTransport = new HttpTransportSE(
                SOAP_ADDRESS_URL);

        try {
            androidHttpTransport.call(SOAP_ACTION, envelope);

            SoapPrimitive response1 = (SoapPrimitive) envelope.getResponse();
            String strRes = response1.toString();
            Log.i("test", "callGetUserByUserName::->" + strRes);

        } catch (SocketTimeoutException t) {
            t.printStackTrace();
        } catch (IOException i) {
            i.printStackTrace();
        } catch (Exception q) {
            q.printStackTrace();
        }

我從webservice得到了響應,我可以看到這是日志。

    <?xml version="1.0" encoding="utf-16"?>
    <NewDataSet>
      <Table>
        <MobileAppUserID>17</MobileAppUserID>
        <UserName>testmit88@gmail.com</UserName>
        <Password>testmit88</Password>
        <Firstname>testmit</Firstname>
        <Lastname>testmit</Lastname>
        <Phone>1234567890</Phone>
        <ResetPW>false</ResetPW>
      </Table>
    </NewDataSet>

如果您得到響應,則在獲得響應后執行此操作。

public **YOUR_RETURN_TYPE** parseObject(SoapObject soapObject)  throws SocketException,SocketTimeoutException,IOException{
        SoapObject _temp = soapObject;

        SoapObject diffgramObject = (SoapObject) _temp.getProperty("diffgram");     
        SoapObject newDataSetObject = (SoapObject) diffgramObject
                .getProperty("NewDataSet");

        if(diffgramObject.hasProperty("NewDataSet"))
        {
            for (int i = 0; i < newDataSetObject.getPropertyCount(); i++) {
                CategoryBean categoryBean = new CategoryBean();

                SoapObject tableObject = (SoapObject) newDataSetObject
                        .getProperty(i);
                SoapPrimitive catId = (SoapPrimitive) tableObject
                        .getProperty("MobileAppUserID");
                categoryBean.setCatId(Integer.valueOf(catId.toString()));
                SoapPrimitive propertyId = (SoapPrimitive) tableObject
                        .getProperty("UserName");
                categoryBean.setPropertyId(Integer.valueOf(propertyId.toString()));         
                SoapPrimitive categoryName = (SoapPrimitive) tableObject
                        .getProperty("Password");
                categoryBean.setCategoryName(categoryName.toString());

                ...........

                //SET DATA TO YOUR COLLECTION OBJECT

            }
            return YOUR_COLLECTION_OBJECT;
        }

    }

暫無
暫無

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

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