2013-06-27 79 views
2

複數排列喜歡:在android中如何使用kso​​ap2庫發送magento中的複雜數組?

$id = "value"; 

$customer = array("key" => "value", "key" => "value"); 

$set = $soap->call($sessionID, 'abc.set', array($id, $customer)); 

如何發送請求形式機器人與這種類型的皁複雜陣列。

我使用ksoap2庫在磁肥皂發送請求。

在調用此類型複雜陣列的像的SOAPUI軟件格式:

<SOAP-ENV:Envelope SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="urn:Magento" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:ns2="http://xml.apache.org/xml-soap" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/"> 
    <SOAP-ENV:Body> 
     <call> 
     <sessionId xsi:type="xsd:string">??</sessionId> 
     <resourcePath xsi:type="xsd:string">abc.set</resourcePath> 
     <args xsi:type="SOAP-ENC:Array"> 
      <item xsi:type="xsd:int">id</item> 
      <item xsi:type="ns2:Map"> 
       <item> 
        <key xsi:type="xsd:string">key</key> 
        <value xsi:type="xsd:string">value</value> 
       </item> 
       <item> 
        <key xsi:type="xsd:string">key</key> 
        <value xsi:type="xsd:string">value</value> 
       </item> 
       <item> 
        <key xsi:type="xsd:string">key</key> 
        <value xsi:type="xsd:string">value</value> 
       </item> 
      </item> 
     </args> 
     </call> 
    </SOAP-ENV:Body> 
</SOAP-ENV:Envelope> 
+0

我得到了解決方案https://groups.google.com/forum/#!topic/ksoap2-android/OeP-jWVLZMw –

回答

0

步驟1:在KSOAP或ksoap2不直接支持送數組。這樣你就可以創建一個方法名SoapObject(你需要創建陣列)

SoapObject object= new SoapObject(NAMESPACE,"shoppingCartProductEntity"); 
object.addProperty("product_id","886"); 
object.addProperty("sku","ABC 456-Black-10"); 
     and more parameters..... 

步驟2:然後創建arrayType中方法(可選取決於你的WSDL),這soapObject添加到該數組對象作爲物業

SoapObject EntityArray = new SoapObject(NAMESPACE, "shoppingCartProductEntityArray"); 
EntityArray.addProperty("products",object); 

步驟3:數組最後添加到您的主SOAP調用

SoapObject request = new SoapObject(NAMESPACE,"shoppingCartProductAdd"); 
request.addProperty("sessionId", sessionId); 
request.addProperty("quoteId", cartId); 
request.addProperty("products",EntityArray); //ADDING ARRAY HERE AS A PEOPERTY 
env.setOutputSoapObject(request); 
androidHttpTransport.call(NAMESPACE +"/shoppingCartProductAdd ", env); 
resultSoap = env.getResponse(); 

注意:步驟取決於您的WSDL,有時您可以直接將第1步對象作爲參數添加,這取決於WSDL。

+0

我試過了,但我得到這個錯誤'SoapFault - faultcode:'1022'faultstring :'請指定產品所需的選項。'。任何解決方案? – Rahul

相關問題