i have this webservice:
[WebMethod]
public string findUserNameById(int Id)
{
return getStudent(Id);
}
public String getStudent(int id)
{
SqlConnection conn;
conn = Class1.ConnectionManager.GetConnection();
conn.Open();
SqlCommand newCmd = conn.CreateCommand();
newCmd.CommandType = CommandType.Text;
newCmd.CommandText = "select * from dbo.tblUser where Id=" + id + "";
SqlDataReader sdr = newCmd.ExecuteReader();
String address = null;
if (sdr.Read())
{
address = sdr.GetValue(0).ToString();
address += "," + sdr.GetValue(1).ToString();
address += "," + sdr.GetValue(2).ToString();
}
conn.Close();
return address;
}
which retrieve row values like this: Id, name, grade. and im calling this webservice from android application:
public class MainActivity extends AppCompatActivity {
private EditText editText;
private TextView textView;
private Handler mHandler= new Handler();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
editText = (EditText)findViewById(R.id.editText);
textView = (TextView)findViewById(R.id.textView);
}
public void getName(View v){
String inputId =editText.getText().toString();
//String[] params= new String[]{"10.0.2.2",inputId};
String[] params= new String[]{"192.168.1.17:90",inputId};
new MyAsyncTask().execute(params);
}
class MyAsyncTask extends AsyncTask<String, Void, String>
{
public String SOAP_ACTION="http://tempuri.org/findUserNameById";
public String OPERATION_NAME ="findUserNameById";
public String WSDL_TARGET_NAMESPACE ="http://tempuri.org/";
public String SOAP_ADDRESS;
private SoapObject request;
private HttpTransportSE httpTransport;
private SoapSerializationEnvelope envelop;
Object response= null;
@Override
protected String doInBackground(String... params) {
SOAP_ADDRESS="http://"+params[0]+"/myWebService.asmx";
request= new SoapObject(WSDL_TARGET_NAMESPACE,OPERATION_NAME);
PropertyInfo pi=new PropertyInfo();
pi.setName("Id");
pi.setValue(Integer.parseInt(params[1]));
pi.setType(Integer.class);
request.addProperty(pi);
pi= new PropertyInfo();
envelop= new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelop.dotNet=true;
envelop.setOutputSoapObject(request);
httpTransport=new HttpTransportSE(SOAP_ADDRESS);
try{
httpTransport.call(SOAP_ACTION,envelop);
response=envelop.getResponse();
}
catch (Exception e){
response=e.getMessage();
}
return response.toString();
}
@Override
protected void onPostExecute(final String result){
super.onPostExecute(result);
mHandler.post(new Runnable() {
@Override
public void run() {
textView.setText(result);
}
});
}
}
I want to fetch all of the rows and display it in a list view in the android, how to do it?
the query will be like : select * from dbo.tblUser
what should i change in the webservice? also what should i do in java for android?