package com.example.gramaniladharidetails;
import java.util.Vector;
import org.ksoap2.SoapEnvelope;
import org.ksoap2.SoapFault;
import org.ksoap2.serialization.KvmSerializable;
import org.ksoap2.serialization.Marshal;
import org.ksoap2.serialization.MarshalFloat;
import org.ksoap2.serialization.PropertyInfo;
import org.ksoap2.serialization.SoapObject;
import org.ksoap2.serialization.SoapSerializationEnvelope;
import org.ksoap2.transport.HttpTransportSE;
import android.os.AsyncTask;
import android.os.Bundle;
import android.app.Activity;
import android.util.Log;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
public class GramaNiladhari extends Activity {
private static String SOAP_ACTION1= "http://localhost/getGramaNiladhariData";
private static String NAMESPACE = "http://119.235.4.217/";
private static String METHOD_NAME1 = "getGramaNiladhariData";
private static String URL = "";
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_grama_niladhari);
b.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
final String gndLifeCode = prov;
String LifeCode = "3-2-09-060";
request.addProperty("gndLifeCode", LifeCode);
SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME1);
SupportThread st = new SupportThread();
Log.i("Request", request.toString());
st.execute(request);
}
});
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.activity_grama_niladhari, menu);
return true;
}
private class SupportThread extends
AsyncTask<SoapObject, Object, SoapObject> {
@Override
protected SoapObject doInBackground(SoapObject... req) {
SoapObject result = null;
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
SoapEnvelope.VER11);
envelope.setOutputSoapObject(req[0]);
envelope.addMapping(NAMESPACE, "SerializeInfo",
new SerializeInfo().getClass());
Marshal floatMarshal = new MarshalFloat();
floatMarshal.register(envelope);
envelope.dotNet = true;
try {
envelope.encodingStyle = SoapSerializationEnvelope.XSD;
HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
androidHttpTransport.debug = true;
androidHttpTransport.call(SOAP_ACTION1, envelope);
SoapObject result = (SoapObject) envelope.getResponse();
if (envelope.bodyIn instanceof SoapFault) {
String str = ((SoapFault) envelope.bodyIn).faultstring;
Log.i("*******", str);
} else {
int elementCount = result.getPropertyCount();
if (elementCount > 0) {
String element;
for (int i = 0; i < elementCount; i++) {
element = result.getProperty(i).toString();
Log.d("This is an element", Integer.toString(i)
+ " --" + element);
}
}
}
} catch (Exception e) {
e.printStackTrace();
}
return result;
}
@Override
protected void onPostExecute(SoapObject result) {
// TODO Auto-generated method stub
super.onPostExecute(result);
if (result != null) {
String response_name = result.getName();
TextView tv = (TextView) findViewById(R.id.textView5);
tv.setText(result.getProperty(0).toString());
}
else {
Toast.makeText(getApplicationContext(), "No Response",
Toast.LENGTH_LONG).show();
}
}
}
}
The webservice method i am calling retuns a complexType Object called GramaNiladhari. It consists of 5 string types. When I run this code I get the following SoapObject result.
anyType{gnName=anyType{}; address=anyType{}; workingDays=anyType{}; gnDivision=anyType{}; contactNumber=anyType{}; }
But here i am missing the values,and they are replaced with anyType{} . How can I retrieve the real values ?
I've edit my question.
This is the parsed request in XML.
<v:Envelope xmlns:i="http://www.w3.org/2001/XMLSchema-instance"
xmlns:d="http://www.w3.org/2001/XMLSchema"
xmlns:c="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:v="http://schemas.xmlsoap.org/soap/envelope/"><v:Header /><v:Body>
<getGramaNiladhariData xmlns="http://119.235.4.217/GNService/">
<gndLifeCode i:type="d:string">1-1-21-065</gndLifeCode>
</getGramaNiladhariData></v:Body></v:Envelope>
And this is the result after calling the web service.
<?xml version="1.0" encoding="utf-8"?> <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"> <soap:Body> <getGramaNiladhariDataResponse xmlns="http://localhost/"> <getGramaNiladhariDataResult><gnName /><address /><workingDays /><gnDivision /><contactNumber /></getGramaNiladhariDataResult></getGramaNiladhariDataResponse></soap:Body></soap:Envelope>
Checking the request,it seems that the request has passed well(even the request parameter gndLifeCode with its correct value, 1-1-21-065 ).
But the response, is null.All the elements I need to retrieve have empty tags.
Can this be a problem in web service. I've checked this web service in SoapUI & it works well there(even it works in SoapClient). Yet can't figure out what the issue here is?