Mushtaq
Mushtaq

Reputation: 29

Web Services for android devices

Following is the code for Web services at android devices. I done exactly the way I watched In a youtube Video. There is no any error showing, still cant get the result on my AVD. The result should be " I am passing a static value in Celsius and need to get Convert the value in Fahrenheit". When I run app on AVD there is nothing happen even though there is no any error too.

package com.example.mushtaqali.testapp1;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
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 org.ksoap2.transport.HttpTransportSE;


import android.widget.TextView;

public class MainActivity extends AppCompatActivity {

    private static final String SOAP_ACTION="http://www.w3schools.com/xml/CelsiusToFahrenheit";
    private static final String METHOD_NAME="CelsiusToFahrenheit";
    private static final String NAMESPACE="http://www.w3schools.com/xml/";
    private static final String URL="http://www.w3schools.com/xml/tempconvert.asmx";
    TextView tv;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        tv=(TextView)findViewById(R.id.textView);

        SoapObject request=new SoapObject(NAMESPACE, METHOD_NAME);
        request.addProperty("Celsius", "32");

        SoapSerializationEnvelope soapEnvelope =new SoapSerializationEnvelope(SoapEnvelope.VER11);
        soapEnvelope.dotNet=true;
        soapEnvelope.setOutputSoapObject(request);

        HttpTransportSE aht=new HttpTransportSE(URL);
        try {
            aht.call(SOAP_ACTION, soapEnvelope);
            SoapPrimitive resultString=(SoapPrimitive)soapEnvelope.getResponse();
            //SoapObject result= (SoapObject)soapEnvelope.bodyIn;
            tv.setText("Status : " +  resultString);
        }
        catch (Exception e){

            e.printStackTrace();
        }
    }
}

Upvotes: 0

Views: 82

Answers (0)

Related Questions