私は石鹸を使ってウェブサービス用のアンドロイドでプログラムを書きました。しかし、私はasynctaskを認識していません。誰かがプログラムの流れを修正できますか。整数値を送信し、Web サービスを介して変換された値を取得する必要があります
package com.example.webservice;
import org.ksoap2.SoapEnvelope;
import org.ksoap2.serialization.PropertyInfo;
import org.ksoap2.serialization.SoapObject;
import org.ksoap2.serialization.SoapPrimitive;
import org.ksoap2.serialization.SoapSerializationEnvelope;
import org.ksoap2.transport.HttpTransportSE;
import com.example.webservice.R.string;
import android.os.AsyncTask;
import android.os.Bundle;
import android.app.Activity;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
public class WebService extends Activity {
private final String NAMESPACE = "http://tempuri.org/";
private final String URL = "http://www.w3schools.com/webservices/tempconvert.asmx?wsdl";
private final String SOAP_ACTION = "http://tempuri.org/CelsiusToFahrenheit";
private final String METHOD_NAME = "CelsiusToFahrenheit";
String celsius="";
Button b;
TextView tv;
EditText et;
String res;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_web_service);
et=(EditText)findViewById(R.id.editText1);
tv=(TextView)findViewById(R.id.Result);
b=(Button)findViewById(R.id.button1);
b.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
//String result=getFarenheit(et.getText().toString());
//tv.setText(result+"°F");
new service().execute();
}
});
}
private class service extends AsyncTask<Void, Void, String>{
@Override
protected String doInBackground(Void... arg0) {
SoapObject request= new SoapObject(NAMESPACE, METHOD_NAME);
PropertyInfo celsuiusPI= new PropertyInfo();
celsuiusPI.setName("Celsius");
celsuiusPI.setValue(celsius);
celsuiusPI.setType(string.class);
request.addProperty(celsuiusPI);
SoapSerializationEnvelope envelope=new SoapSerializationEnvelope (SoapEnvelope.VER11);
envelope.dotNet=true;
envelope.setOutputSoapObject(request);
HttpTransportSE androidHttpTransport=new HttpTransportSE(URL);
try{
androidHttpTransport.call(SOAP_ACTION, envelope);
SoapPrimitive response=(SoapPrimitive)envelope.getResponse();
Log.i("WebService output", response.toString());
res= response.toString();
}
catch(Exception e){
e.printStackTrace();
}
return res;
}
protected void onPostExecute(String h){
String result=h;
tv.setText(result+"°F");
}
}
}
痕跡
11-15 18:38:08.045: W/Trace(823): Unexpected value from nativeGetEnabledTags: 0
11-15 18:38:08.065: W/Trace(823): Unexpected value from nativeGetEnabledTags: 0
11-15 18:38:08.065: W/Trace(823): Unexpected value from nativeGetEnabledTags: 0
11-15 18:38:08.515: W/Trace(823): Unexpected value from nativeGetEnabledTags: 0
11-15 18:38:08.515: W/Trace(823): Unexpected value from nativeGetEnabledTags: 0
11-15 18:38:08.546: W/Trace(823): Unexpected value from nativeGetEnabledTags: 0
11-15 18:38:08.546: W/Trace(823): Unexpected value from nativeGetEnabledTags: 0
11-15 18:38:09.130: W/Trace(823): Unexpected value from nativeGetEnabledTags: 0
11-15 18:38:09.130: W/Trace(823): Unexpected value from nativeGetEnabledTags: 0
11-15 18:38:09.167: W/Trace(823): Unexpected value from nativeGetEnabledTags: 0
11-15 18:38:09.167: W/Trace(823): Unexpected value from nativeGetEnabledTags: 0
11-15 18:38:09.685: W/Trace(823): Unexpected value from nativeGetEnabledTags: 0
11-15 18:38:09.685: W/Trace(823): Unexpected value from nativeGetEnabledTags: 0
11-15 18:38:09.736: W/Trace(823): Unexpected value from nativeGetEnabledTags: 0
11-15 18:38:09.736: W/Trace(823): Unexpected value from nativeGetEnabledTags: 0
11-15 18:38:10.235: W/Trace(823): Unexpected value from nativeGetEnabledTags: 0
11-15 18:38:10.235: W/Trace(823): Unexpected value from nativeGetEnabledTags: 0
11-15 18:38:10.255: W/Trace(823): Unexpected value from nativeGetEnabledTags: 0
11-15 18:38:10.255: W/Trace(823): Unexpected value from nativeGetEnabledTags: 0
11-15 18:38:10.801: W/Trace(823): Unexpected value from nativeGetEnabledTags: 0
11-15 18:38:10.801: W/Trace(823): Unexpected value from nativeGetEnabledTags: 0
11-15 18:38:10.825: W/Trace(823): Unexpected value from nativeGetEnabledTags: 0
11-15 18:38:10.825: W/Trace(823): Unexpected value from nativeGetEnabledTags: 0