Pass ArrayList data into SOAP web service in android
Try this code:
SoapObject request = new SoapObject(Wsdl_Target_NameSpace,
Method_Name);
for (int i = 0; i < Property_Key.size(); i++) {
request.addProperty(Property_Key.get(i), Property_Value.get(i));
}
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
SoapEnvelope.VER11);
envelope.setOutputSoapObject(request);
HttpTransportSE androidHttpTransport = null;
androidHttpTransport = new HttpTransportSE(Url_location);
androidHttpTransport.call(Soap_Action, envelope);
SoapObject results = (SoapObject) envelope.bodyIn;
Vector response = (Vector) envelope.getResponse();
How to pass a String array to a webservice using soap libraries?
It is a known issue with the KSOAP2 for Android library, which at the moment simply doesn't support arrays. The issue description is here.
A third-party patch, solution and an example can be found here.
Look on these link, You can find your answer on that.
Send data from Android to Web Service (via SOAP)
Try using SOAP Envelope for sending data,
Syntax for SOAP Envelope:
final String envelope = "<?xml version=\"1.0\" encoding=\"utf-8\"?>"+
"<SOAP-ENV:Envelope SOAP-ENV:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\" " +
"xmlns:SOAP-ENV=\"http://schemas.xmlsoap.org/soap/envelope/\" " +
"xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" " +
"xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"" +
" xmlns:SOAP-ENC=\"http://schemas.xmlsoap.org/soap/encoding/\" " +
"xmlns:tns=\"urn:registerwsdl\">"+
"<SOAP-ENV:Body>"+
"<tns:register " +
"xmlns:tns=\"urn:registerwsdl\">"+
"<your_feild_name xsi:type=\"xsd:string\">"+"your_value"+"</your_feild_name>"+
"</tns:register>"+
// "</SOAP-ENV:Body></SOAP-ENV:Envelope>",Name,Email,Password,Status,Type,Date];
"</SOAP-ENV:Body></SOAP-ENV:Envelope>";
and then use this envelop in this function,
you can pass multiple value with Soap Envelope
String CallWebService(String url,
String soapAction,
String envelope) {
final DefaultHttpClient httpClient=new DefaultHttpClient();
// request parameters
HttpParams params = httpClient.getParams();
HttpConnectionParams.setConnectionTimeout(params, 20000);
HttpConnectionParams.setSoTimeout(params, 25000);
// set parameter
HttpProtocolParams.setUseExpectContinue(httpClient.getParams(), true);
// POST the envelope
HttpPost httppost = new HttpPost(url);
// add headers
httppost.setHeader("soapaction", soapAction);
httppost.setHeader("Content-Type", "text/xml; charset=utf-8");
String responseString="";
try {
// the entity holds the request
HttpEntity entity = new StringEntity(envelope);
httppost.setEntity(entity);
// Response handler
ResponseHandler<String> rh=new ResponseHandler<String>() {
// invoked when client receives response
public String handleResponse(HttpResponse response)
throws ClientProtocolException, IOException {
// get response entity
HttpEntity entity = response.getEntity();
// read the response as byte array
StringBuffer out = new StringBuffer();
byte[] b = EntityUtils.toByteArray(entity);
// write the response byte array to a string buffer
out.append(new String(b, 0, b.length));
return out.toString();
}
};
responseString=httpClient.execute(httppost, rh);
}
catch (Exception e) {
Log.v("exception", e.toString());
}
xml = responseString.toString();
// close the connection
System.out.println("xml file ------"+xml);
httpClient.getConnectionManager().shutdown();
return responseString;
}
and in the end parse the XML output by using any XML parser.
Passing string array to c# web service (Android Ksoap2)
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;
}
Related Topics
Android - Navigation View Item Menu Background Color
Should Use "Sp" Instead of "Dp" for Text Sizes
Bufferoverflowexception When Building Application
Using Intent.Action_Pick for Specific Path
Which Port and Protocol Does Google Cloud Messaging (Gcm) Use
How to Handle One-Shot Operations in Jetpack Compose
Android 4.2: Back Stack Behaviour with Nested Fragments
Custom Global Application Class Breaks with "Android.App.Application Cannot Be Cast To"
Android: Why Must Use Getbasecontext() Instead of This
Get Last Inserted Value from SQLite Database Android
How to Raise a Toast in Asynctask, I am Prompted to Used the Looper
Set Language to French in Android Datepickerdialog
Android Options Menu Icon Won't Display
Out of Memory Exception Due to Large Bitmap Size