【发布时间】:2014-07-10 07:43:41
【问题描述】:
我正在尝试使用 ksoap2 在远程 Magento 安装上创建订单。我能够使用 SOAP v2 Api 执行基本操作,但我遇到了复杂性对象。
这是我试图与之交互的 wsdl 的一部分
<complexType name="shoppingCartProductEntityArray">
<complexContent>
<restriction base="soapenc:Array">
<attribute ref="soapenc:arrayType" wsdl:arrayType="typens:shoppingCartProductEntity[]"/>
</restriction>
</complexContent>
</complexType>
<complexType name="shoppingCartProductResponseEntityArray">
<complexContent>
<restriction base="soapenc:Array">
<attribute ref="soapenc:arrayType" wsdl:arrayType="typens:catalogProductEntity[]"/>
</restriction>
</complexContent>
</complexType>
.....
<message name="shoppingCartProductAddRequest">
<part name="sessionId" type="xsd:string"/>
<part name="quoteId" type="xsd:int"/>
<part name="products" type="typens:shoppingCartProductEntityArray"/>
<part name="storeId" type="xsd:string"/>
</message>
.....
<operation name="shoppingCartProductAdd">
<documentation>Add product(s) to shopping cart</documentation>
<input message="typens:shoppingCartProductAddRequest"/>
<output message="typens:shoppingCartProductAddResponse"/>
</operation>
我尝试了以下
env = getEnvelope();
request = new SoapObject(NAMESPACE, MethodName_AddProduct);
request.addProperty("sessionId",_SessionId );
SoapObject SingleProduct = new SoapObject(NAMESPACE, "shoppingCartProductEntity");
PropertyInfo pi = new PropertyInfo();
pi.setName("product_id");
pi.setValue(Products[0][0]);
pi.setType(String.class);
SingleProduct.addProperty(pi);
pi = new PropertyInfo();
pi.setName("sku");
pi.setValue(Products[0][1]);
pi.setType(String.class);
SingleProduct.addProperty(pi);
pi = new PropertyInfo();
pi.setName("qty");
pi.setValue(1);
pi.setType(Double.class);
SingleProduct.addProperty(pi);
SoapObject EntityArray = new SoapObject(NAMESPACE, "shoppingCartProductEntityArray");
EntityArray.addProperty("productData",SingleProduct);
request.addProperty("quoteId",cartId);
request.addProperty("productsData",EntityArray);
env.setOutputSoapObject(request);
androidHttpTransport = new HttpTransportSE(URL);
androidHttpTransport.call(SoapAction_AddProduct, env);
但我收到以下消息
SoapFault - faultcode: '1021' faultstring: '产品的数据不是 有效的。' faultactor:'null' 详细信息:null
我还尝试打印对我来说格式正确的请求
调试请求: shoppingCartProductAdd{sessionId=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx; 报价ID=31; productsData=shoppingCartProductEntityArray{productData=shoppingCartProductEntity{product_id=1; 货号=PLM01;数量=1; }; }; }
【问题讨论】:
-
我认为您需要传递您的 wsdl 中提到的相同参数名称
-
你到底指的是什么? wsdl 声明 shoppingCartProductEntityArray 应该命名为 products,对吧?