1

我是新的安卓。我尝试使用 ksoap。我通过一个罐子添加了这些库。我认为一切正常,但我的代码不起作用。如果我评论 ksoap 代码一切正常。我不明白是什么问题?请帮我。代码如下:

package com.hndnn;

import org.ksoap2.SoapEnvelope;
import org.ksoap2.serialization.SoapObject;
import org.ksoap2.serialization.SoapPrimitive;
import org.ksoap2.serialization.SoapSerializationEnvelope;
import org.ksoap2.transport.AndroidHttpTransport;
import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;

public class TermometreActivity extends Activity {
final static String NAMESPACE = "http://tempuri.org/";

    final static String METHOD_NAME = "CelsiusToFahrenheit";

    final static String SOAP_ACTION = "http://tempuri.org/CelsiusToFahrenheit";

    final static String URL = "http://www.w3schools.com/webservices/tempconvert.asmx";
    TextView txt;

    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        txt=(TextView) findViewById(R.id.textView1);
       SoapObject Request=new SoapObject(NAMESPACE, METHOD_NAME);
        Request.addProperty("Celsius", "20");
        SoapSerializationEnvelope sse=new SoapSerializationEnvelope(SoapEnvelope.VER11);
       sse.dotNet=true;
       sse.setOutputSoapObject(Request);
       AndroidHttpTransport aht=new AndroidHttpTransport(URL);
        try {
            aht.call(SOAP_ACTION, sse);
            SoapPrimitive sonuc= (SoapPrimitive) sse.getResponse();
            txt.setText("Derece:"+sonuc);
            //txt.setText("try içinde");``

        } catch (Exception e) {
          e.printStackTrace();
          txt.setText("handan");
        }
4

0 回答 0