Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to 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 16-May-12 23:21pm
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

try this
 

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;
		}
	}
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

thanks Smile | :) it is working. Smile | :) my first android project is this project Smile | :)
  Permalink  

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

  Print Answers RSS
Your Filters
Interested
Ignored
     
0 Shai Vashdi 1,518
1 Tadit Dash 350
2 Manas Bhardwaj 319
3 OriginalGriff 243
4 Sergey Alexandrovich Kryukov 205
0 Sergey Alexandrovich Kryukov 9,530
1 OriginalGriff 5,716
2 Peter Leow 4,320
3 Maciej Los 3,540
4 Abhinav S 3,373


Advertise | Privacy | Mobile
Web01 | 2.8.140415.2 | Last Updated 18 May 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Use
Layout: fixed | fluid