package com.example.dotnwebservice; import org.ksoap2.SoapEnvelope; import org.ksoap2.serialization.PropertyInfo; import org.ksoap2.serialization.SoapObject; import org.ksoap2.serialization.SoapSerializationEnvelope; import org.ksoap2.transport.AndroidHttpTransport; public class WebserviceCall { //String namespace = "http://www.webserviceX.NET/"; String namespace = "http://tempuri.org/ConvertWeight/ConvertWeight"; //private String url = "http://www.webservicex.net/ConvertWeight.asmx"; private String url = "http://192.168.1.10/Ws/Service1.asmx"; String SOAP_ACTION; SoapObject request = null, objMessages = null; SoapSerializationEnvelope envelope; AndroidHttpTransport androidHttpTransport; WebserviceCall() { } /** * Set Envelope */ protected void SetEnvelope() { try { // Creating SOAP envelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11); //You can comment that line if your web service is not .NET one. envelope.dotNet = true; envelope.setOutputSoapObject(request); androidHttpTransport = new AndroidHttpTransport(url); androidHttpTransport.debug = true; } catch (Exception e) { System.out.println("Soap Exception---->>>" + e.toString()); } } // MethodName variable is define for which webservice function will call public String getConvertedWeight(String MethodName, String weight, String fromUnit, String toUnit) { try { SOAP_ACTION = namespace + MethodName; //Adding values to request object request = new SoapObject(namespace, MethodName); //Adding Double value to request object PropertyInfo weightProp =new PropertyInfo(); weightProp.setName("Weight"); weightProp.setValue(weight); weightProp.setType(double.class); request.addProperty(weightProp); //Adding String value to request object request.addProperty("FromUnit", "" + fromUnit); request.addProperty("ToUnit", "" + toUnit); SetEnvelope(); try { //SOAP calling webservice androidHttpTransport.call(SOAP_ACTION, envelope); //Got Webservice response String result = envelope.getResponse().toString(); return result; } catch (Exception e) { // TODO: handle exception return e.toString(); } } catch (Exception e) { // TODO: handle exception return e.toString(); } } /************************************/ }
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.Services; using System.Web.Script.Services; namespace AndroidDemoService { /// <summary> /// Summary description for Service1 /// </summary> [WebService(Namespace = "http://tempuri.org/")] [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)] [System.ComponentModel.ToolboxItem(false)] // 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 Service1 : System.Web.Services.WebService { [WebMethod] [ScriptMethod(ResponseFormat = ResponseFormat.Json)] public string getConvertedWeight(String MethodName, String weight,String fromUnit, String toUnit) { string SA = "hey this is test"; return SA; } } }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)