我想知道如何在我的 Soap 调用方法中使用字符串信封。这是我的信封:
String soapEnvelope = "<soap:Envelope xmlns:soap=\"http://www.w3.org/2003/05/soap-envelope\" xmlns:tem=\"http://tempuri.org\">\n"
+ "<soap:Header/>\n"
+ "<soap:Body>\n"
+ "<tem:GetItems>\n"
+ "<tem:catId>"+categoryId+"</tem:catId>\n"
+ "</tem:GetItems>\n"
+ "</soap:Body>\n"
+ "</soap:Envelope>\n";
我通常使用
SoapObject request = new SoapObject(NAMESPACE, METHODNAME_MAINCATEGORIES);
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.dotNet = true;
envelope.setOutputSoapObject(request);
HttpTransportSE httpTransportSe = new HttpTransportSE(URL);
httpTransportSe.debug = true;
SoapObject response = null;
try{
httpTransportSe.call(SOAP_ACTION, envelope);
response = (SoapObject)envelope.getResponse();
SoapObject main = (SoapObject)response.getProperty(1);
SoapObject list = (SoapObject)main.getProperty(0);
//String a = Integer.toString(list.getPropertyCount());
//Log.i("property count", a);
for(int i = 0; i<list.getPropertyCount(); i++){
Categories c = new Categories();
SoapObject nsoap = (SoapObject)list.getProperty(i);
if(nsoap != null){
c.setId(nsoap.getProperty("Id").toString());
c.setMainId(nsoap.getProperty("MainID").toString());
c.setName(nsoap.getProperty("Name").toString());
}
}
}
catch(Exception e){
e.printStackTrace();
}
return categories;
种方法。但是我需要在这个调用中添加一个参数,它是一个整数值。我试图添加
request.addParameter("myValue", myValue);
其中 myValue 是调用此函数所需的参数。以下是部分代码:
public ArrayList<Item> getItems(int myValue){
SoapObject request = new SoapObject(NAMESPACE, METHODNAME_ITEMS);
request.addProperty("myValue", myValue);
Log.i("catId", String.valueOf(myValue));
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.dotNet = true;
envelope.setOutputSoapObject(request);
HttpTransportSE httpTransportSe = new HttpTransportSE(URL);
httpTransportSe.debug = true;
SoapObject response = null;
我尝试了 String 和int myValue params
,请求始终返回为“myValue”0(即使您输入 1、2、3、4 等,它也会返回 0 的项目)。我进行了一项研究并了解到我需要创建一个信封并在那里提供我的参数。现在我创建了一个上面给出的字符串信封,我将如何将它集成到我的通话中?感谢您的回答!