Themabewertung:
  • 0 Bewertung(en) - 0 im Durchschnitt
  • 1
  • 2
  • 3
  • 4
  • 5
ksoap2 tutorial
#1
Hallo Leute,



ich versuche mich gerade an der ksoap2, um auf webservices zugreifen zu koennen. Ich hab mal ein tutorial gemacht und es funktioniert leider nicht.



Code:
// Soap object parameter initialization

    // SOAP_ACTION: You build this from "NAMESPACE string" +

    // "METHOD_NAME string"

    // METHOD_NAME: User provided, you get this from the wsdl

    // NAMESPACE: User provided, you get this from the wsdl

    // URL: User provider, you get this from the wsdl

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

    TextView tv;



    public void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);

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



        SoapObject Request = new SoapObject(NAMESPACE, METHOD_NAME);

        Request.addProperty("Celsius", "32");



        // PART 4

        // Create SOAP Envelope and serialize webservice XML object

        SoapSerializationEnvelope soapEnvelope = new SoapSerializationEnvelope(

                SoapEnvelope.VER11);

        soapEnvelope.dotNet = true;

        soapEnvelope.setOutputSoapObject(Request);

        AndroidHttpTransport tns = new AndroidHttpTransport(URL);

        try {

            // PART 8

            // Make the Web Service Call

            tns.call(SOAP_ACTION, soapEnvelope);



            // PART 9

            // Extract the response from the Web Service Object

            SoapPrimitive result = (SoapPrimitive) soapEnvelope.getResponse();



            // Print out response

            tv.setText("Quote Results: " + result);

        } catch (Exception e)



        {

            e.printStackTrace();

        }



    }



der result ist null - > NullPointerException. Weiss vielleicht zufaellig jemand, was ich vergessen habe?



LG



Asuka
Zitieren
#2
Hi,



füge doch einfach mal:



8<----------------------------

setContentView(R.layout.main);

---------------------------->8



nach "super.onCreate(savedInstanceState);" ein. Dann sollte es klappen.



GruŸ



Chiver
Zitieren


Gehe zu:


Benutzer, die gerade dieses Thema anschauen: 1 Gast/Gäste