1

I want to know how can i use a String envelope in my Soap call method. Here is my envelope :

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";

I normally use

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;

kind of approach. But i need to add a parameter to this call, which is an integer value. I tried to add

request.addParameter("myValue", myValue);

where myValue is a parameter required to call this function. Here is portion of code:

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;

I tried both String and int myValue params, request always returns as "myValue" 0 (it returns items for 0 even if you enter 1,2,3,4 etc.). I made a research and learned that I need to create an envelope and give my parameter there. Now i created a String envelope that I gave above, how will i integrate it to my call ? Thanks for answers !

Mel
  • 1,730
  • 17
  • 33

1 Answers1

0

try adding parameters are follows

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);
Nakul
  • 1,313
  • 19
  • 26
  • Thanks for answer, but i also tried that one before, result is still same, returning like my parameter is 0 on every parameter. – Mel Mar 10 '14 at 13:06
  • are you using KSOAP2 library ? – Nakul Mar 10 '14 at 13:13
  • Yes, "ksoap2-android-assembly-3.1.1-jar-with-dependencies.jar". – Mel Mar 10 '14 at 13:15
  • try using this "ksoap2-android-assembly-3.0.0-jar-with-dependencies.jar" as i have also faced some problems on 3.1.1 version. – Nakul Mar 10 '14 at 13:26
  • I was able to make it work with request.addProperty by fixing my Namespace, it was "http://tempuri.org", while it had to be "http://tempuri.org/". A singe "/" was causing trouble. Thanks for help ! – Mel Mar 11 '14 at 07:50