HttpTransportSE .call() method has no action

前端 未结 1 1527
情深已故
情深已故 2021-01-21 17:12

I\'m trying to make an Android App that gets the weather based off a zipcode you enter, and that also displays the time in EST and GMT format. I am using webservices (WSDLs) and

相关标签:
1条回答
  • 2021-01-21 17:49

    !!!! WORKING CONFIRMED !!!

    main

    public class MainActivity extends Activity{
    
    public static String rslt,thread;
    SoapMiddleMan c;
    
    EditText txtZIP;
    TextView weather;
    
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    
        setContentView(R.layout.activity_main);     
    
        txtZIP = (EditText)findViewById(R.id.zipCode);
        weather = (TextView)findViewById(R.id.weather);
    
      }
    
    public void sendMessage(View view)
    {
        try{
                // condition for keeping the main thread asleep
                thread = "START";
    
                // create a new webservice caller thread
                c = new SoapMiddleMan();
    
                // join the new thread, start it and then select what webservice you want to access
                c.join();c.setZip(txtZIP.getText().toString()); c.start();
    
                // keep this thread asleep while the service thread is running
                while(thread=="START")
                {   
                    try
                        {
                            Thread.sleep(10);
                        }
                    catch(Exception e)
                        {
                            rslt="Failed2";
                        }
                }
            }
    
        catch(Exception e)
        {
            e.printStackTrace();
        }
    
        weather.setText(rslt);
    }
    }
    

    middleman

    public class SoapMiddleMan extends Thread {
    
    private String zip;
    private SoapSenderClass cs;
    
    public void run(){
    
        try{
             cs=new SoapSenderClass();
             String resp=cs.getWeather(zip);
             MainActivity.rslt=resp; //public string in calling activity
             System.out.println("reached 2 \n");
            }catch(Exception ex)
    
            {
                MainActivity.rslt=ex.toString();
            }
    
    
            MainActivity.thread = "done";
        }
    
    public void setZip(String searchZip)
    {
        zip = searchZip;
    }
    
    }
    

    Caller

    public class SoapSenderClass{
    
    String SOAP_ACTION = "http://ws.cdyne.com/WeatherWS/GetCityWeatherByZIP";
    String NAMESPACE = "http://ws.cdyne.com/WeatherWS/";
    String METHOD_NAME = "GetCityWeatherByZIP";
    String URL = "http://wsf.cdyne.com/WeatherWS/Weather.asmx?wsdl";
    
    
    public String getWeather(String zipcode)
    {
        try{
        SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
    
        SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
    
        envelope.dotNet = true;
    
        PropertyInfo property = new PropertyInfo();
    
        property.setName("ZIP");
        property.setType(String.class);
        property.setValue(zipcode);
        request.addProperty(property);
    
        envelope.setOutputSoapObject(request);
    
        HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
    
        androidHttpTransport.call(SOAP_ACTION, envelope);
    
        SoapObject response = (SoapObject)envelope.getResponse();
    
        String resultValue = response.toString();
    
        return resultValue;
    
    } 
    catch (Exception e) {
        e.printStackTrace();
        return "Failed to get ID";
    }
    
    }
    }
    

    I have simplified your caller code and I changed the name of the addproperty to ZIP which is what it looks like the input is called in the WSDL. Removed the brackets for the property calls removed Namespace which isnt needed as far as I can tell.

    0 讨论(0)
提交回复
热议问题