public class WebServis extends AppCompatActivity {
ProgressDialog pDialog;
// Web Servisimizdeki Namspace alanı
private final String _Namspace = "http://tempuri.org/";
// Web Servimizdeki Method ismi
private final String _MethodName = "methodname";
// Namspace ile Method isminin birleşimi
private final String _Action = "http://tempuri.org/"+_MethodName;
// Web Servisimizin Adresi
private final String _Url = "http://"ip&or&domain"/WebService/Service.asmx";
private String _ResultValue = "";
Context context;
EditText _birinci_sayi,_ikinci_sayi;
String a,b;
String TAG = "Response";
String resultString;
Object object=null;
//priv JSONArrayAdapter getListView;
private ListView lv;
ArrayList contactList;
Button _btn_topla;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_web_servis);
// Topla butonumuzu tanımlıyoruz.
_btn_topla=(Button)findViewById(R.id.button);
// Yukarıda tanımladığımız _btn_topla butonuna tıklama olayını tanımlıyoruz.
lv= (ListView)findViewById(R.id.listView);
_btn_topla.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
//Hazırladığımız AsyncTask'ımızı çalıştırıyoruz..
AsyncCallWS task = new AsyncCallWS();
task.execute();
}
});
}
// Arkaplanda webservis işlemlerimizi yaptığımız yer.
// AsyncTask sınıfımızdan _WebServiceAsyncTask türetiyoruz..
private class AsyncCallWS extends AsyncTask<Void, Void, Void> {
@Override
protected void onPreExecute() {
Log.i(TAG, "onPreExecute");
}
@Override
protected Void doInBackground(Void... params) {
Log.i(TAG, "doInBackground");
calculate();
HashMap<String, String> contact = new HashMap<>();
showData(resultString);
return null;
}
@Override
protected void onPostExecute(Void result) {
super.onPostExecute(result);
Log.i(TAG, "onPostExecute"+ resultString);
Log.i(TAG, "Step 9");
try {
ListAdapter adapter = new SimpleAdapter(
WebServis.this, contactList,
R.layout.list_order, new String[]{"name", "email",
"adres"}, new int[]{R.id.Name,
R.id.Email, R.id.Adres});
Log.i(TAG, "Step 10");
lv.setAdapter(adapter);
Log.i(TAG, "Step 11");
} catch (Exception e) {
Toast.makeText(getApplicationContext(),"Hata" + e.toString(),Toast.LENGTH_SHORT).show();
e.printStackTrace();
}
}
}
public void calculate() {
String SOAP_ACTION = _Action;
String METHOD_NAME = _MethodName;
String NAMESPACE = _Namspace;
String URL = _Url;
try {
//PropertyInfo propertyInfo=new PropertyInfo();
SoapObject Request = new SoapObject(NAMESPACE, METHOD_NAME);
Request.addProperty("TABLENAME","USER_TBL");
Request.addProperty("COLUMNS","USERID,NAME,PASS,EPOSTA,ADRESS");
Request.addProperty("WHERECRTR","");
Request.addProperty("TOP","");
Request.addProperty("COLUMN","");
SoapSerializationEnvelope soapEnvelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
soapEnvelope.dotNet = true;
//soapEnvelope.headerOut = security; // this is an Element[] created before
soapEnvelope.setOutputSoapObject(Request);
HttpTransportSE transport = new HttpTransportSE(URL);
transport.debug=true;
transport.call(SOAP_ACTION, soapEnvelope);
SoapPrimitive response = (SoapPrimitive) soapEnvelope.getResponse();
//resultString1 = (SoapPrimitive) soapEnvelope.getResponse();
resultString =response.toString();
Log.i(TAG, "Result Celsius: " + resultString);
} catch (Exception ex) {
// Log.e(TAG, "Error: " + ex.getMessage());
}
}
private void showData(String json) {
String jsonStr = json;
Log.e(TAG, "Response from json: " + jsonStr);
if (jsonStr != null) {
try {
JSONObject jsonObj = new JSONObject(jsonStr);
// Getting JSON Array node
JSONArray contacts = jsonObj.getJSONArray("USER_TBL");
// looping through All Contacts
contactList = new ArrayList<HashMap<String, String>>();
for (int i = 0; i < contacts.length(); i++) {
JSONObject c = contacts.getJSONObject(i);
String id = c.getString("USERID");
String name = c.getString("NAME");
String email = c.getString("EPOSTA");
String address = c.getString("ADRESS");
String pass = c.getString("PASS");
HashMap<String, String> contact = new HashMap<String, String>();
contact.put("id", id);
contact.put("name", name);
contact.put("email", email);
contact.put("adres", address);
contact.put("pass", pass);
//contact.put("mobile", mobile);
// adding contact to contact list
contactList.add(contact);
}
} catch (final JSONException e) {
Log.e(TAG, "Json parsing error: " + e.getMessage());
runOnUiThread(new Runnable() {
@Override
public void run() {
Toast.makeText(getApplicationContext(),
"Json parsing error: " + e.getMessage(),
Toast.LENGTH_LONG)
.show();
}
});
}
} else {
Log.e(TAG, "Couldn't get json from server.");
runOnUiThread(new Runnable() {
@Override
public void run() {
Toast.makeText(getApplicationContext(),
"Couldn't get json from server. Check LogCat for possible errors!",
Toast.LENGTH_LONG)
.show();
}
});
}
}
}