skip to main |
skip to sidebar
RSS Feeds
Nope. nothing .. just some random thoughts come to my mind ...
Nope. nothing .. just some random thoughts come to my mind ...
5:41 PM | Sunday, June 9, 2013
Posted by harshadura
Whoever getting started to learn Web services - Android app interaction I hope this tutorial may be helpful, You can download the full source from here: https://github.com/harshadura/RDA-Android-ASP.WS-interact/archive/master.zip
Prerequisites:
.NET framework, SQL server 2008, Android device/emulator
How to run.
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.Services; using System.Data; using System.Data.Sql; using System.Data.SqlClient; [WebService(Namespace = "http://tempuri.org/")] [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
public class Service : System.Web.Services.WebService { public Service () { //Uncomment the following line if using designed components //InitializeComponent(); } [WebMethod] public String GetEmployeeByID(String id) { DataSet2TableAdapters.EmployeeTableAdapter dt1 = new DataSet2TableAdapters.EmployeeTableAdapter(); String ename = "" + dt1.getEmpByID(id); return ename; } [WebMethod] public Employee[] GetEmployees() { var employees = new List(); try { string connect = @"Data Source=HARSHADURA-AZUS\SQLEXPRESS;Initial Catalog=RDA;Integrated Security=True"; string query = "SELECT eid, ename FROM Employee"; SqlConnection thisConnection = new SqlConnection(connect); thisConnection.Open(); SqlCommand thisCommand = thisConnection.CreateCommand(); thisCommand.CommandText = query; SqlDataReader thisReader = thisCommand.ExecuteReader(); while (thisReader.Read()) { var emp = new Employee(); emp.eid = thisReader["eid"].ToString(); emp.ename = thisReader["ename"].ToString(); employees.Add(emp); } thisReader.Close(); thisConnection.Close(); } catch (SqlException e) { Console.WriteLine(e.Message); } return employees.ToArray(); } }
private SoapObject result = null; private static String SOAP_ACTION = "http://tempuri.org/GetEmployeeByID"; private static String NAMESPACE = "http://tempuri.org/"; private static String METHOD_NAME = "GetEmployeeByID"; private static String URL = "http://192.168.123.100:8080/Service.asmx?WSDL"; public void connectSOAP(String empid) { SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME); request.addProperty("id", empid); SoapSerializationEnvelope envelope = new SoapSerializationEnvelope( SoapEnvelope.VER11); envelope.dotNet = true; envelope.setOutputSoapObject(request); HttpTransportSE androidHttpTransport = new HttpTransportSE(URL); try { androidHttpTransport.call(SOAP_ACTION, envelope); } catch (Exception e) { e.printStackTrace(); } result = (SoapObject) envelope.bodyIn; }
December 4, 2014 at 12:25 PM
hw do i use this example with gennymotion
March 25, 2016 at 3:29 PM
good