我正在开发Soap api上的android应用程序。我用来处理api的库是Ksoap2。
要发送数据以将Grouped产品添加到购物车,我在SoapUI中发送这样的数据:
<soapenv:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:urn="urn:Magento" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/">
<soapenv:Header/>
<soapenv:Body>
<urn:shoppingCartProductAdd soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<sessionId xsi:type="xsd:string">513922303bd9a731a29ac1ac419bfbfb</sessionId>
<quoteId xsi:type="xsd:int">716</quoteId>
<products xsi:type="urn:shoppingCartProductEntityArray" soapenc:arrayType="urn:shoppingCartProductEntity[]">
<shoppingCartProductEntity>
<product_id>555</product_id>
<qty>1</qty>
<super_group>
<associativeEntity>
<key>547</key>
<value>1</value>
</associativeEntity>
</super_group>
</shoppingCartProductEntity>
</products>
<storeId xsi:type="xsd:string">1</storeId>
</urn:shoppingCartProductAdd>
</soapenv:Body>
</soapenv:Envelope>
&#13;
并使用Ksoap2库,我发送的数据如下:
@Override
protected String doInBackground(String... params) {
Log.v("onExecute", "Inside On execute");
SoapObject request = new SoapObject(NAMESPACE, "shoppingCartProductAdd");
request.addProperty("sessionId", "513922303bd9a731a29ac1ac419bfbfb");
request.addProperty("quoteId","716");
request.addProperty("storeId","1");
SoapObject products = new SoapObject(NAMESPACE,"shoppingCartProductEntity");
products.addProperty("product_id","555");
products.addProperty("qty","1");
SoapObject options = new SoapObject(NAMESPACE,"super_group");
SoapObject associativeEntity = new SoapObject(NAMESPACE,"associativeEntity");
associativeEntity.addProperty("key","547");
associativeEntity.addProperty("value","1");
options.addSoapObject(associativeEntity);
SoapObject product1 = new SoapObject(NAMESPACE,"shoppingCartProductEntityArray");
products.addProperty("super_group",options);
product1.addProperty("associativeEntity",products);
request.addProperty("products",product1);
SoapSerializationEnvelope soapEnvelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
soapEnvelope.dotNet = false;
soapEnvelope.setOutputSoapObject(request);
HttpTransportSE transport = new HttpTransportSE(URL, 30000);
try {
Log.v("DebuggingCount", "1");
transport.call(SOAP_ACTION, soapEnvelope);
Log.v("DebuggingCount", "2");
object = soapEnvelope.bodyIn;
Log.v("ObjectBodyIn", "" + object);
if (object instanceof SoapObject) {
SoapObject soapObject = (SoapObject) soapEnvelope.bodyIn;
Log.v("SoapObjectBodyIn", "" + soapObject);
SoapObject resultString = (SoapObject) soapEnvelope.getResponse();
Log.v("asddsffg",""+resultString);
} else if (object instanceof SoapFault) {
if (((SoapFault) object).faultcode.equals("5")) {
} else if (((SoapFault) object).faultcode.equals("4")) {
} else if (((SoapFault) object).faultcode.equals("3")) {
} else if (((SoapFault) object).faultcode.equals("2")) {
} else if (((SoapFault) object).faultcode.equals("1")) {
}
}
} catch (SocketTimeoutException e1) {
Log.v("SocketTimeOut", "Inside STO");
} catch (ConnectException ce) {
Log.v("ConnectSocket", "Inside CT");
} catch (Exception e) {
Log.v("ExceptionOccured: ", "" + e.getMessage());
Log.v("ExceptionOccured: ", "" + e.getClass());
}
return null;
}
结果实现了,但是当我使用SoapUI添加带有自定义选项的简单产品时,我发送的内容如下:
<soapenv:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:urn="urn:Magento" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/">
<soapenv:Header/>
<soapenv:Body>
<urn:shoppingCartProductAdd soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<sessionId xsi:type="xsd:string">513922303bd9a731a29ac1ac419bfbfb</sessionId>
<quoteId xsi:type="xsd:int">716</quoteId>
<products xsi:type="urn:shoppingCartProductEntityArray" soapenc:arrayType="urn:shoppingCartProductEntity[]">
<shoppingCartProductEntity>
<product_id>908</product_id>
<qty>1</qty>
<options>
<associativeEntity>
<key>68</key>
<value>Apple</value>
</associativeEntity>
</options>
</shoppingCartProductEntity>
</products>
<storeId xsi:type="xsd:string">1</storeId>
</urn:shoppingCartProductAdd>
</soapenv:Body>
</soapenv:Envelope>
&#13;
结果实现了。但主要的问题是当我使用Ksoap2库发送相同的数据时,我收到faultCode:1022和faultstring:&#39;请指定产品所需的选项。我使用自定义选项发送简单产品的代码如下:
@Override
protected String doInBackground(String... params) {
Log.v("onExecute", "Inside On execute");
SoapObject request = new SoapObject(NAMESPACE, "shoppingCartProductAdd");
request.addProperty("sessionId", "513922303bd9a731a29ac1ac419bfbfb");
request.addProperty("quoteId","716");
request.addProperty("storeId","1");
SoapObject products = new SoapObject(NAMESPACE,"shoppingCartProductEntity");
products.addProperty("product_id","908");
products.addProperty("qty","1");
SoapObject options = new SoapObject(NAMESPACE,"options");
SoapObject associativeEntity = new SoapObject(NAMESPACE,"associativeEntity");
associativeEntity.addProperty("key","68");
associativeEntity.addProperty("value","shubham");
options.addSoapObject(associativeEntity);
SoapObject product1 = new SoapObject(NAMESPACE,"shoppingCartProductEntityArray");
products.addProperty("options",options);
product1.addProperty("associativeEntity",products);
request.addProperty("products",product1);
SoapSerializationEnvelope soapEnvelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
soapEnvelope.dotNet = false;
soapEnvelope.setOutputSoapObject(request);
HttpTransportSE transport = new HttpTransportSE(URL, 30000);
try {
Log.v("DebuggingCount", "1");
transport.call(SOAP_ACTION, soapEnvelope);
Log.v("DebuggingCount", "2");
object = soapEnvelope.bodyIn;
Log.v("ObjectBodyIn", "" + object);
if (object instanceof SoapObject) {
SoapObject soapObject = (SoapObject) soapEnvelope.bodyIn;
Log.v("SoapObjectBodyIn", "" + soapObject);
SoapObject resultString = (SoapObject) soapEnvelope.getResponse();
Log.v("asddsffg",""+resultString);
} else if (object instanceof SoapFault) {
if (((SoapFault) object).faultcode.equals("5")) {
} else if (((SoapFault) object).faultcode.equals("4")) {
} else if (((SoapFault) object).faultcode.equals("3")) {
} else if (((SoapFault) object).faultcode.equals("2")) {
} else if (((SoapFault) object).faultcode.equals("1")) {
}
}
} catch (SocketTimeoutException e1) {
Log.v("SocketTimeOut", "Inside STO");
} catch (ConnectException ce) {
Log.v("ConnectSocket", "Inside CT");
} catch (Exception e) {
Log.v("ExceptionOccured: ", "" + e.getMessage());
Log.v("ExceptionOccured: ", "" + e.getClass());
}
return null;
}
数据库中需要68。
请帮助,今天我试图找出错误并没有得到任何结果。我浪费了一整天。