2

this is my code that I write to call webservice using this video. When I run it, I received an Error string instead of 89.6.

package com.flafel.myTest;

import android.app.Activity;
import android.net.http.AndroidHttpClient;
import android.os.Bundle;
import org.ksoap2.serialization.SoapObject;
import org.ksoap2.serialization.SoapPrimitive;
import org.ksoap2.serialization.SoapSerializationEnvelope;
import org.ksoap2.transport.HttpTransportSE;
import org.ksoap2.SoapEnvelope;
import android.widget.*;

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

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);


                tv = (TextView) findViewById(R.id.textView1);

                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);
                aht.debug=true;


                try {

                    aht.call(SQAP_ACTION, soapEnvelope);

                    SoapPrimitive resultString = (SoapPrimitive) soapEnvelope
                            .getResponse();
                    int count = resultString.getAttributeCount();
                    tv.setText("Status:" + resultString);

                } catch (Exception e) {
                    e.printStackTrace();
                }

            }       
}

The output is :

Hello World,FirstScreen!
Status:Error

1 Answer 1

1

Because you didn't write method_name to own place.

Your code:

SoapObject Request = new SoapObject(NAMESPACE, "Method_Name");

True code:

SoapObject Request = new SoapObject(NAMESPACE, METHOD_NAME);
Sign up to request clarification or add additional context in comments.

1 Comment

i fix it sorry i wong text :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.