在Ksaop Android上使用String Envelope

时间:2014-03-10 12:52:29

标签: android soap envelope

我想知道如何在Soap调用方法中使用String信封。这是我的信封:

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项)。我做了一项研究并了解到我需要创建一个信封并在那里给出我的参数。现在我创建了一个我在上面给出的String信封,我将如何将它集成到我的呼叫中?谢谢你的回答!

1 个答案:

答案 0 :(得分:0)

尝试添加参数如下

SoapObject request = new SoapObject(NAMESPACE, METHODNAME_ITEMS);
PropertyInfo paraId = new PropertyInfo();
paraId.setName("YOUR PARAMETER NAME");
paraId.setValue("YOUR PARAMETER VALUE");
paraId.namespace=NAMESPACE;
paraId.setType(String.class); // or INTEGER whatever your type is...
request.addProperty(wallpaperCatId);