android中的ksoap请求格式?

问题描述 投票:0回答:1

我有基于 Magento 的 SOAP+XML Web 服务。我正在使用 ksoap2 作为库 Web 服务调用。现在,下面是我的 API 的 magento 请求格式,其名称为“customer.list”

<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding" xmlns:ns1="urn:Magento" xmlns:ns2="http://xml.apache.org/xml-soap" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding">
   <SOAP-ENV:Body>
      <ns1:call>
         <sessionId xsi:type="xsd:string">(My Seesion ID)</sessionId>
         <resourcePath xsi:type="xsd:string">customer.list</resourcePath>
         <args SOAP-ENC:arrayType="ns2:Map[1]" xsi:type="SOAP-ENC:Array">
            <item xsi:type="ns2:Map">
               <item>
                  <key xsi:type="xsd:string">email</key>
                  <value xsi:type="xsd:string">(User Email ID)</value>
               </item>
            </item>
         </args>
      </ns1:call>
   </SOAP-ENV:Body>
</SOAP-ENV:Envelope>

我尝试使用此代码,但主要的是我希望根据给定的电子邮件 ID 对所有用户进行归档,就像我只想要单个用户的数据,该用户的电子邮件 ID 与我请求的电子邮件 ID 匹配,问题出在我的编码上它响应所有用户列表,因此我的请求的参数部分不符合 magento 的请求格式。我是基于 SOAP 的 Web 服务的新手,所以,如果有人知道,请给我一些解释。下面的代码是我尝试过的,我

SoapSerializationEnvelope soapEnvelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
soapEnvelope.implicitTypes = true;
soapEnvelope.dotNet = true;
soapEnvelope.avoidExceptionForUnknownProperty=true;
soapEnvelope.setAddAdornments(false);
SoapObject soapReq = new SoapObject("urn:Magento", "call");
soapReq.addProperty("sessionId", sessionId);
 String NESTED_NAMESPACE = "http://schemas.microsoft.com/2003/10/Serialization/Arrays";
SoapObject recipients = new SoapObject(NESTED_NAMESPACE, "args");

Vector<String> recp = new Vector<String>();
recp.add("email");
recipients.addProperty("key", recp);
recp = new Vector<String>();
recp.add("[email protected]");
recipients.addProperty("value", recp);
soapReq.addSoapObject(recipients);
soapEnvelope.setOutputSoapObject(recipients);
HttpTransportSE httpTransport = new HttpTransportSE(url, timeOut);
httpTransport.debug = true;
try {
if (headers != null) {
httpTransport.call("urn:Magento/call", soapEnvelope, headers);
} else {
httpTransport.call("urn:Magento/call", soapEnvelope);
}
Object retObj = soapEnvelope.bodyIn;
Object result = null;
try {
result = soapEnvelope.getResponse();
} catch (SoapFault soapFault) {
soapFault.printStackTrace();
}
android magento soap ksoap2 magento-soap-api
1个回答
2
投票

我已经解决了我的问题,我认为我的问题不值得负分。无论如何,我正在上传我的解决方案,如下所示,

SoapSerializationEnvelopesoapEnvelope=newSoapSerializationEnvelope(SoapEnvelope.VER11);
soapEnvelope.dotNet=true;
soapEnvelope.implicitTypes=true;
soapEnvelope.setAddAdornments(false);
SoapObjectsoapReq=newSoapObject(NAMESPACE,"call");
soapReq.addProperty("sessionId",sessionId);
soapReq.addProperty("resourcePath","customer.list");
SoapObjectnewObj=newSoapObject();
newObj.addProperty("key","email");
newObj.addProperty("value","[email protected]");
newObj.addAttribute("i:type","ns2:Map");
SoapObjectFINALoBJ=newSoapObject();
FINALoBJ.addProperty("item",newObj);
SoapObjectmain_obj=newSoapObject();
main_obj.addProperty("item",FINALoBJ);
main_obj.addAttribute("xmlns:ns2","http://xml.apache.org/xml-soap");
main_obj.addAttribute("i:type","c:Array");
main_obj.addAttribute("c:arrayType","ns2:Map[1]");
soapReq.addProperty("args",main_obj);
soapEnvelope.setOutputSoapObject(soapReq);
HttpTransportSEhttpTransport=newHttpTransportSE(url,timeOut);
httpTransport.debug=true;
try{
if(headers!=null){
httpTransport.call("urn:Magento/call",soapEnvelope,headers);
}else{
httpTransport.call("urn:Magento/call",soapEnvelope);
}
ObjectretObj=soapEnvelope.bodyIn;
Objectresult=null;
try{
result=soapEnvelope.getResponse();
}catch(SoapFaultsoapFault){
soapFault.printStackTrace();
}
© www.soinside.com 2019 - 2024. All rights reserved.