2016-08-02 60 views
0

我必須調用一個Web服務,通​​過kSoap2方法調用Web服務,現在在這一個節點中是一個子對象,所以我可以通過它。KSoap2通過子對象

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:tem="http://tempuri.org/"> 
    <soapenv:Header/> 
    <soapenv:Body> 
     <tem:AddDataVersion2> 
     <!--Optional:--> 
     <tem:object> 
      <!--Optional:--> 
      <tem:Data1>?</tem:Data1> 
      <!--Optional:--> 
      <tem:Data2>?</tem:Data2> 
      <!--Optional:--> 
      <tem:Data3>?</tem:Data3> 
      <!--Optional:--> 
      <tem:Data4>?</tem:Data4> 
     <tem:object> 
     </tem:AddDataVersion2> 
    </soapenv:Body> 
</soapenv:Envelope> 

此子對象=如何將數據添加到對象,並添加對象

SoapObject request = new SoapObject(NAMESPACE,"tem:AddDataVersion2"); 
     request.addProperty("Data1", 1); 
     request.addProperty("Data2", 2); 
     request.addProperty("Data3", 3); 
     request.addProperty("Data4", 4); 

回答

0

你不應該把數據放到addProperty()方法直接。相反,您需要將數據添加到PropertyInfo對象中,並將該對象添加到SoapObject中作爲property。在你的情況 -

對於防爆:

SoapObject request = new SoapObject(NAMESPACE,"tem:AddDataVersion2"); 
PropertyInfo propertyInfo1= new PropertyInfo(); 
propertyInfo.setName("Data1"); 
propertyInfo.setValue("1"); 
propertyInfo.setType(String.class); 

PropertyInfo propertyInfo2= new PropertyInfo(); 
propertyInfo.setName("Data2"); 
propertyInfo.setValue("2"); 
propertyInfo.setType(String.class); 

PropertyInfo propertyInfo3= new PropertyInfo(); 
propertyInfo.setName("Data3"); 
propertyInfo.setValue("3"); 
propertyInfo.setType(String.class); 

PropertyInfo propertyInfo4= new PropertyInfo(); 
propertyInfo.setName("Data4"); 
propertyInfo.setValue("4"); 
propertyInfo.setType(String.class); 

request.addProperty(propertyInfo1); 
request.addProperty(propertyInfo2); 
request.addProperty(propertyInfo3); 
request.addProperty(propertyInfo4); 

希望這將有助於:)