HttpTransportSE .call() 方法没有任何动作

HttpTransportSE .call() method has no action

我正在尝试制作一个 Android 应用程序,它根据您输入的邮政编码获取天气信息,并且还以 EST 和 GMT 格式显示时间。我正在使用网络服务 (WSDL) 并编写了访问它的代码,代码如下:

public void sendMessage(View view)
{
    SOAP_ACTION = "http://ws.cdyne.com/WeatherWS/GetCityWeatherByZIP";
    NAMESPACE = "http://ws.cdyne.com/WeatherWS/";
    METHOD_NAME = "GetCityWeatherByZIP";
    URL = "http://wsf.cdyne.com/WeatherWS/Weather.asmx?wsdl";

    txtZIP = (EditText) findViewById(R.id.zipcode);
    temp = (TextView) findViewById(R.id.displayTemp);
    SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);

    PropertyInfo property = new PropertyInfo();
    {
        property.name = "zipcode";
        property.setNamespace(NAMESPACE);
        property.type = PropertyInfo.STRING_CLASS;
        property.setValue(txtZIP.getText().toString());
    }

    request.addProperty(property);

    //request.addProperty("zipcode", txtZIP.getText().toString());

    Toast.makeText(getApplicationContext(), "btnZIP pressed", Toast.LENGTH_LONG).show();
    SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER10);
    envelope.setOutputSoapObject(request);
    envelope.implicitTypes = true;
    envelope.dotNet = true;
    HttpTransportSE androidHTTP = new HttpTransportSE(URL, 600);

    try {
        Toast.makeText(getApplicationContext(), "In try statement", Toast.LENGTH_LONG).show();

        androidHTTP.call(SOAP_ACTION, envelope);

        // SoapPrimitive resp = (SoapPrimitive) envelope.getResponse();
        SoapObject result = (SoapObject) envelope.bodyIn;

        if(result != null)
        {
            Toast.makeText(getApplicationContext(), "In IF statement", Toast.LENGTH_LONG).show();
            //temp.append("in IF statement, result not null");
        } else {
            Toast.makeText(getApplicationContext(), "In ELSE statement", Toast.LENGTH_LONG).show();
            //temp.append("in IF statement, result IS null");
        }

    } catch (HttpResponseException e) {
        Toast.makeText(getApplicationContext(), "No Response", Toast.LENGTH_LONG).show();
        e.printStackTrace();
    } catch (XmlPullParserException e){
        Toast.makeText(getApplicationContext(), "XML Pull exe", Toast.LENGTH_LONG).show();
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    } catch (Exception e) {
        e.printStackTrace();
    }
}

现在,我的问题是 androidHTTP.call(SOAP_ACTION, envelope); 方法没有任何反应。我有 Toast 方法来显示正在执行的内容,我得到的最远是进入 try 块,但从未进入 if 语句。

我已经尝试四处寻找可能的原因和解决方案,但我似乎无法找到针对此特定问题的任何信息。我已将服务器的超时时间延长到 600,甚至将 implicitType 设置为 true,但没有任何效果。我知道我为此方法使用了 SoapEnvelope.VER10,但我还有其他两种方法,我使用了 VER11 和 VER12,并且没有任何变化。如果有人对可能发生的事情有任何想法,我将非常感谢您的帮助。此外,AndroidManifest.xml 具有访问互联网所需的使用许可行。

!!!!确认工作 !!!

主要

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

中间人

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

}

来电者

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";
}

}
}

我已经简化了您的调用方代码,并将 add属性 的名称更改为 ZIP,这看起来像是在 WSDL 中调用的输入。删除了 属性 调用的括号删除了据我所知不需要的命名空间。