package com.example.dotnwebservice;
import org.ksoap2.SoapEnvelope;
import org.ksoap2.serialization.PropertyInfo;
import org.ksoap2.serialization.SoapObject;
import org.ksoap2.serialization.SoapPrimitive;
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/";
//private String url = "http://www.webservicex.net/ConvertWeight.asmx";
//private String url = "http://192.168.1.10/Ws/Service1.asmx";
private String url = "http://192.168.1.3/vs/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 ConvertWeight(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();
}
}
/************************************/
}
here is my android code for calling web service
and
.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Web.Script.Services;
namespace AndroidDemoService
{
[WebService(Namespace = "http://tempuri.org/ConvertWeight")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.ComponentModel.ToolboxItem(false)]
public class Service1 : System.Web.Services.WebService
{
[WebMethod]
[ScriptMethod(ResponseFormat = ResponseFormat.Json)]
public string ConvertWeight(String MethodName, String weight, String fromUnit, String toUnit)
{
if (weight == "" || weight == null)
{
string SA = "No Weight Received";
return SA;
}
else
{
int W1 = Convert.ToInt32(weight.ToString());
int weight1 = W1 / 1000;
string SA = weight1.ToString();
return weight;
}
}
}
}
above is my asp.net service code i m able to getting result of this web service in android
but wen i passing parameter from my app to service web service could not giving a result.
here in my webservice
only if part of that is working but else part is not working when i am passing parameters