首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >getResponse()上出现错误

getResponse()上出现错误
EN

Stack Overflow用户
提问于 2013-01-22 13:11:22
回答 1查看 768关注 0票数 1

我是android的新手,我正在尝试web服务的一个例子。我用过ksoap2库。我关注了一段视频,输入了以下代码:

代码语言:javascript
复制
package example.web;

import android.R.anim;
import android.app.Activity;
import android.os.Bundle;
import org.ksoap2.*;
import org.ksoap2.serialization.*;
import org.ksoap2.transport.*;
import android.widget.TextView;

public class First extends Activity {
/** Called when the activity is first created. */
    TextView tv;
    private static final String                SOAP_ACTION="http://tempuri.org/CelsiusToFahrenheit";
    private static final String METHOD_NAME="CelsiusToFahrenheit";
    private static final String NAMESPACE="http://tempuri.org/";
    private static final String URL="http://www.w3schools.com/webservices/tempconvert.asmx";

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        tv = (TextView) findViewById(R.id.textView1);

        // creating the soap request and all its paramaters
        SoapObject request= new SoapObject(NAMESPACE, METHOD_NAME);
        request.addProperty("Celsius","32");// hardcoding some random value
        //we can also take in a value in a var and pass it there


        //set soap envelope,set to dotnet and set output
        SoapSerializationEnvelope soapEnvelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
        soapEnvelope.dotNet=true;
        soapEnvelope.setOutputSoapObject(request);

        HttpTransportSE obj = new HttpTransportSE(URL);
        //to make call to server
        try {
            obj.call(SOAP_ACTION,soapEnvelope);// in out parameter
        SoapPrimitive resultString=(SoapPrimitive)SoapEnvelope.getResponse();
        tv.setText("Status : " + resultString);
        }
        catch(Exception e) {
        e.printStackTrace();
        }
    }
}

SoapPrimitive resultString=(SoapPrimitive)SoapEnvelope.getResponse();

在上面的代码行中,我在getResponse();上遇到错误,请谁来帮帮我。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-01-22 14:24:12

尝试将您的 SoapEnvelope 更改为 soapEnvelope ,并在SoapObject而不是 SoapPrimitive中获得结果

代码语言:javascript
复制
try
{
    obj.call(SOAP_ACTION,soapEnvelope);// in out parameter
    SoapObject resultString = (SoapObject) soapEnvelope.getResponse();
    tv.setText("Status : " + resultString);
}
catch (Exception e) 
{
    SoapObject resultString = (SoapObject)soapEnvelope.bodyIn; 
}

希望它能帮到你!

票数 -1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/14451955

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档