Click here to Skip to main content
15,891,136 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
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
.

C#
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/ConvertWeight")]
    [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 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;
            }
            //string SA = "hey this is test from nikunj.";

        }
    }
}




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
Posted

1 solution

i find a problem that is in name space in webservice


[WebService(Namespace = "http://tempuri.org/ConvertWeight")] instade of this

use [WebService(Namespace = "http://tempuri.org/ConvertWeight/")]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900