1

私はアンドロイドが初めてで、Webサービスの一例を試しています。ksoap2 lib を使用しました。私は1つのビデオをたどり、次のコードを入力しました:

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(); ています。誰か助けてください。

4

1 に答える 1

-1

に変更して、代わりに内部で結果を取得しSoapEnvelope みてくださいsoapEnvelope SoapObject SoapPrimitive

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

お役に立てば幸いです!!

于 2013-01-22T06:24:12.073 に答える