2

复杂数组如:

$id = "value";

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

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

如何在soap中使用这种类型的复杂数组发送请求表单android。

我正在使用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>
4

1 回答 1

0

第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 作为属性添加到该数组对象

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

第 3 步:最后将数组添加到您的主肥皂调用中

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,有时您可以直接添加 1st step 对象作为参数,这取决于 WSDL。

于 2014-09-22T12:23:40.997 回答