我在SOAP + XML中使用基于Magento的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>
我尝试使用此代码,但主要的是我希望filer所有用户按照我给定的电子邮件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();
}
答案 0 :(得分: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","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();
}