以下是 android 设备上的 Web 服务代码。我完全按照我在 youtube 视频中观看的方式完成了。没有任何错误显示,仍然无法在我的 AVD 上得到结果。结果应该是“我正在传递一个摄氏温度的静态值,需要转换华氏温度的值”。当我在 AVD 上运行应用程序时,即使没有任何错误也没有任何反应。
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();
}
}
}