0

我想使用 Android 的网络服务。它是由创建.net framework.url="http://www.deeptraining.com/webservices/weather.asmx"但未运行的天气 Web 服务。我做错了什么?

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());
                }

            }

        });
    }
}
4

0 回答 0