【问题标题】:ksoap request format in android?android中的ksoap请求格式?
【发布时间】:2015-08-20 05:05:48
【问题描述】:

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

<?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("xyz@abc.com");
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 web-services magento soap ksoap2


    【解决方案1】:

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

    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","xyz@abc.com");
    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();
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多