I am trying to develop an android application which can access values stored in sql server database through a Web Service.My Web Service returns null response(like anyType{}) if it has arguments. Web Methods without arguments works fine.This is my Web Service
[WebMethod]
public List<string> getDetails(string dist)
{
details = new List<string>();
string sel = "select h_Name,h_address,h_contact from hospital_tb where h_district='" + dist + "'";
SqlDataReader dr = db.dataRead(sel);
while (dr.Read())
{
string name = dr["h_name"].ToString();
string adres = dr["h_address"].ToString();
string contact = dr["h_contact"].ToString();
result = name + ":" + adres + ":" + contact;
details.Add(result);
}
return details;
}
Web Service NameSpace is:http://hospitalsearch.com/hos
Here is my Android Code
class Async extends AsyncTask<String, String, String>
{
@Override
protected String doInBackground(String... params) {
// TODO Auto-generated method stub
request=new SoapObject(NAMESPACE, METHOD);
property=new PropertyInfo();
property.setName("district");
property.setValue(dis);
Log.d("condition", dis);
request.addProperty(property);
SoapSerializationEnvelope envelope=new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.dotNet=true;
envelope.bodyOut=request;
Log.d("ree", request.toString());
HttpTransportSE transport=new HttpTransportSE(ADDRESS);
try {
transport.call(ACTION, envelope);
//SoapPrimitive response=(SoapPrimitive)envelope.getResponse();
response=(SoapObject)envelope.getResponse();
Log.d("response", response.toString());
if(response!=null)
{
parseData(response);
}
else
{
Log.d("result", "no data");
}
} catch (IOException e) {
// TODO Auto-generated catch block
res="error";
Log.d("result", res);
e.printStackTrace();
} catch (XmlPullParserException e) {
// TODO Auto-generated catch block
res="error1";
Log.d("result", res);
e.printStackTrace();
}
return res;
}
@Override
protected void onPostExecute(String result) {
// TODO Auto-generated method stub
ll.setAdapter(adapter);
}
public void parseData(SoapObject result)
{
for(int i=0;i<result.getPropertyCount();i++)
{
if(result.getProperty(i) instanceof SoapObject)
{
parseData((SoapObject)result.getProperty(i));
}
else
{
PropertyInfo p=new PropertyInfo();
result.getPropertyInfo(i, p);
String name= result.getProperty(i).toString();
Log.d("data", name);
String[] re=name.split(":");
Model model=new Model();
model.setName(re[0]);
model.setAddress(re[1]);
model.setContact(re[2]);
al.add(model);
}
}
}
}
Here i found that web service not receiving the parameter that i passed from my Android Code.I also Log my Request:Log.d("request", request.toString());and it shows getDetails{districts=AAAA}.