2

Hi so i've been searching google for a while and but can't seem to have a solid example for this. I've been working with webservice this past few days with android and I can succesfully pass parameters from android and consume it back with ksoap with no problems. But now I need to pass an array to a webservice. So heres my sample web service:

[WebMethod]
public string Sample(string[] logs)
{
    return array[0];
}

And this is the XML that I need to generate:

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
  <soap:Body>
    <Sample xmlns="http://MTKAndroidService.org/">
      <array>
        <string>string</string>
        <string>string</string>
      </array>
    </Sample>
  </soap:Body>
</soap:Envelope>

I've been stuck with this for a while now and hope someone can help me.

2
  • 1
    what about just passing a comma-delimited string, then using string[] array = String.Split(",",input); Commented Aug 19, 2013 at 2:16
  • thank you for the reply. Yes i already ventured into that option but the string would be too long if i did it that way. We are talking of upto 100 string values here so i dont really think its best to use that technique Commented Aug 19, 2013 at 7:03

1 Answer 1

4

Finally Got it....for those who is stuck on this also ill post my answer

public String Sample()
    { 
        String SOAP_ACTION = "http://MTKAndroidService.org/Sample";
        String METHOD_NAME = "Sample";
//      URL =  "http://10.0.2.2:49923/Service1.asmx";   // to be adjusted to the URL above once this code is added into WebService;
        String IP_LIST="";
        SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME); 
        List<String> logs =  new ArrayList<String>();
        logs.add("hello");
        logs.add("world");
        SoapObject soapLogs = new SoapObject(NAMESPACE, "logs");
        for (String i : logs){
            soapLogs.addProperty("string", i);
        }
        request.addSoapObject(soapLogs);

        SoapSerializationEnvelope IPenvelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
        IPenvelope.dotNet = true;
        IPenvelope.setOutputSoapObject(request);
        HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);

            try 
            {
                androidHttpTransport.call(SOAP_ACTION, IPenvelope);
                SoapPrimitive response = (SoapPrimitive)IPenvelope.getResponse();
                Log.i("myApp", response.toString());
                IP_LIST= response.toString();
            } 
            catch (Exception e) 
            {
                e.printStackTrace();
            }
            return IP_LIST;
    }
Sign up to request clarification or add additional context in comments.

3 Comments

@TheProvots:pls. refer this link[stackoverflow.com/questions/19198017/…) Do you have any idea how can i send this type of data to soap service
Hi sorry been a long time since i logged in...anyway are you still having problem with this? i cannot seem to access your page

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.