且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

在机器人如何在Magento使用kso​​ap2库发送复杂的阵列?

更新时间:2023-11-07 20:58:22

第1步:在KSOAP或ksoap2不直接支持发送阵列。这样你就可以创建一个方法名SoapObject(您需要创建数组)

  SoapObject对象=新SoapObject(命名空间shoppingCartProductEntity);
中Object.addProperty(PRODUCT_ID,886);
中Object.addProperty(SKU,ABC 456黑10);
         多参数.....
 

第二步:,然后创建arrayType中方法(可选取决于您的WSDL),这soapObject添加到该数组对象为属性

  SoapObject EntityArray =新SoapObject(命名空间shoppingCartProductEntityArray);
EntityArray.addProperty(产品,对象);
 

第三步:终于在阵列中添加到您的主SOAP调用

  SoapObject请求=新SoapObject(命名空间shoppingCartProductAdd);
request.addProperty(的sessionId的sessionId);
request.addProperty(quoteId,cartId);
request.addProperty(产品,EntityArray); // ADDING ARRAY这里作为一个PEOPERTY
env.setOutputSoapObject(要求);
androidHttpTransport.call空间(namespace +/ shoppingCartProductAdd,ENV);
resultSoap = env.getResponse();
 

注:以下步骤改变依赖于你的WSDL,有时可以直接加入第一步对象作为参数,这依赖于WSDL

Complex Array Like :

$id = "value";

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

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

How to send request form android with this type of complex array in soap.

I am using ksoap2 library for sending request in magneto soap.

In SoapUi Software formatting of calling this type of complex array like :

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

Step 1 : In ksoap or ksoap2 no direct support to send Array. so you can create a SoapObject with method name(which you need to create array)

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

Step 2 : then create arrayType method(optional depends on your WSDL) and add this soapObject to that array Object as a property

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

Step 3 : finally add the array to your main soap call

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();

NOTE : the steps varies depends on the your WSDL, sometimes you can directly add 1st step object as a parameter, this depends on WSDL.