编程语言
首页 > 编程语言> > java-在android中如何使用kso​​ap2库在magento中发送复杂数组?

java-在android中如何使用kso​​ap2库在magento中发送复杂数组?

作者:互联网

复杂数组如:

$id = "value";

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

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

如何在Soap中使用这种复杂数组发送请求表单android.

我正在使用kso​​ap2库在磁香皂中发送请求.

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

解决方法:

步骤1:在ksoap或ksoap2中,不直接支持发送Array.因此您可以使用方法名称创建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作为属性添加到该数组Object

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,有时您可以直接添加第一步对象作为参数,这取决于WSDL.

标签:ksoap2,android,java,php,magento
来源: https://codeday.me/bug/20191012/1898317.html