HttpTransportSE .CALL()方法没有任何作用 [英] HttpTransportSE .call() method has no action

查看:290
本文介绍了HttpTransportSE .CALL()方法没有任何作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图做一个Android应用程序获取基于掀起了拉链code你输入的天气,这也显示在EST和GMT格式的时间。我使用的Web服务(WSDL文件),并有code写入访问时,code是如下:

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 have the code written to access it, the code is below:

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,信封); 方法,什么都没发生。我有面包的方法来显示正在执行什么,我得到的是最远到try块,但从来没有进入if语句。

Now, my problem is that with the androidHTTP.call(SOAP_ACTION, envelope); method, nothing is happening. I have Toast methods to show what is being executed, and the furthest I get is into the try block, but never into the if statement.

我曾尝试环顾四周看到的可能是原因和解决办法,但我似乎无法找到这一特定问题的东西。我已经延长了超时服务器600和还送implicitType为真,但没有什么工作。我知道我使用SoapEnvelope.VER10这个方法,但我有我曾经VER11和VER12而且也没有变化的其他两种方法。如果任何人可能有一个想法,可能什么的,我真的AP preciate的帮助。此外,AndroidManifest.xml中有必要的使用许可权一行访问互联网。

I have tried looking around seeing what might be the cause and a solution, but I can't seem to find anything for this specific problem. I've extended the time-out for the server to 600 and even made the implicitType to true, but nothing is working. I know I am using SoapEnvelope.VER10 for this method, but I have two other methods where I used VER11 and VER12 and there's no change. If anyone might have an idea as to what might be going on, I'd really appreciate the help. Also, the AndroidManifest.xml has the necessary uses-permission line to access the internet.

推荐答案

!!!!工作CONFIRMED!

!!!! WORKING CONFIRMED !!!

主要

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

}
}

我已经简化了您的主叫code和我改变了方法addProperty的名称ZIP这是什么样子的输入被称为在WSDL。删除了括号,据我可以告诉它需要心不是物业电话中删除命名空间。

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.

这篇关于HttpTransportSE .CALL()方法没有任何作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆