Click here to Skip to main content
15,886,840 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
i want to using web service from android. it is weather web service which is creating by .net framework.url="http://www.deeptraining.com/webservices/weather.asmx" And it isnt running.what did i do wrong?

package my.Weather.Package;
import org.ksoap2.SoapEnvelope;
import org.ksoap2.serialization.SoapObject;
import org.ksoap2.serialization.SoapSerializationEnvelope;
import org.ksoap2.transport.HttpTransportSE;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

public class WeatherWebServiceActivity extends Activity {
    private static final String NAMESPACE = "http://litwinconsulting.com/webservices/";
    private static final String URL = "http://www.deeptraining.com/webservices/weather.asmx?WSDL";  
    private static final String SOAP_ACTION = "http://litwinconsulting.com/webservices/GetWeather";
    private static final String METHOD_NAME = "GetWeather";

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        final Button btn_weather = (Button) findViewById(R.id.btnGetWeather);
        final EditText txtCity = (EditText) findViewById(R.id.txtCity);
        final TextView lblWeather=(TextView) findViewById(R.id.lblWeather);

        btn_weather.setOnClickListener(new View.OnClickListener() {

            public void onClick(View v) {

                SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);    
                request.addProperty("City","Miami");
                SoapSerializationEnvelope envelope = 
                    new SoapSerializationEnvelope(SoapEnvelope.VER11); 
                envelope.dotNet=true;
                envelope.setOutputSoapObject(request);
                HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);

                try 
                {
                    androidHttpTransport.call(SOAP_ACTION, envelope);
                    SoapObject result=(SoapObject)envelope.getResponse();
                    lblWeather.setText(result.getProperty(0).toString());
                } 
                catch (Exception e)
                {

                    lblWeather.setText(e.getMessage());
                }

            }

        });
    }
}
Posted

try this


Java
public static String GetWeather(String City) {

		final String METHOD_NAME = "GetWeather";
		final String SOAP_ACTION = "http://litwinconsulting.com/webservices/GetWeather";
		final String NAMESPACE = "http://litwinconsulting.com/webservices/";
		final String URL = "http://www.deeptraining.com/webservices/weather.asmx";

		try {

			SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);

			request.addProperty("City", City);

			SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
					SoapEnvelope.VER11);
			envelope.dotNet = true;
			envelope.encodingStyle = SoapSerializationEnvelope.ENC;
			envelope.setOutputSoapObject(request);

			AndroidHttpTransport androidHttpTransport = new AndroidHttpTransport(
					URL);
			androidHttpTransport
					.setXmlVersionTag("");
			androidHttpTransport.debug = true;
			androidHttpTransport.call(SOAP_ACTION, envelope);

			if (envelope.getResponse() != null
					&& !envelope.getResponse().equals("")) {
				return envelope.getResponse().toString();
			} else {
				return null;
			}
		} catch (Exception e) {
			return null;
		}
	}
 
Share this answer
 
thanks :) it is working. :) my first android project is this project :)
 
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