based on the design of your web server, you either use a quiet connection or soap, and then send your data via HTTP to your web service and get the desired response from it. I wrote an asp web service for a soapy approach, which I will explain below.
Here is an example java code for the soap standard:
private static String NameSpace = "http://tempuri.org/"; //below url must be your service url, mine is a local one private static String URL = "http://192.168.2.213/hintsservice/service.asmx"; private static String SOAP_ACTION = "http://tempuri.org/"; public static String Invoke(String s) { //respond string from server String resTxt = ""; //the name of your web service method final String webMethName = "Hint"; // Create request SoapObject request = new SoapObject(NameSpace, webMethName); // Property which holds input parameters PropertyInfo PI = new PropertyInfo(); // Set Name PI.setName("s"); // Set Value PI.setValue(s); // Set dataType PI.setType(String.class); // Add the property to request object request.addProperty(PI); // Create envelope SoapSerializationEnvelope envelope = new SoapSerializationEnvelope( SoapEnvelope.VER11); //Set envelope as dotNet envelope.dotNet = true; // Set output SOAP object envelope.setOutputSoapObject(request); // Create HTTP call object HttpTransportSE androidHttpTransport = new HttpTransportSE(URL); try { // Invoke web servi.ce androidHttpTransport.call(SOAP_ACTION + webMethName, envelope); // Get the response SoapPrimitive response = (SoapPrimitive) envelope.getResponse(); // Assign it to resTxt variable static variable resTxt = response.toString(); }catch (Exception e) { //Print error e.printStackTrace(); //Assign error message to resTxt resTxt = "Error occured"; } //Return resTxt to calling object return resTxt; }
now you just need to call this method from the appropriate activity and let your web service do the rest. Here is an example C # web service:
[WebService(Namespace = "http://tempuri.org/")] [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)] // To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line. [System.Web.Script.Services.ScriptService] public class Service : System.Web.Services.WebService { public Service () { //Uncomment the following line if using designed components //InitializeComponent(); [WebMethod] public string Hint(string s) { string response = string.Empty; //todo: produce response return response; } } }
Ami nadimi
source share