我正在使用 tempconvert Web 服务,但它没有给出任何结果,只是显示空白屏幕。
这是否意味着我的应用程序无法访问 Web 服务,或者我必须进行一些设置才能连接到 URL,我使用的是 ksoap2 2.6.5 。
这是我的代码
package com.example.webservice2;
import android.os.Bundle;
import android.widget.TextView;
import android.app.Activity;
import org.ksoap2.*;
import org.ksoap2.serialization.SoapObject;
import org.ksoap2.serialization.SoapPrimitive;
import org.ksoap2.serialization.SoapSerializationEnvelope;
import org.ksoap2.transport.HttpTransportSE;
public class WebService extends Activity {
private final String SOAP_ACTION = "http://tempuri.org/CelsiusToFahrenheit";
private final String METHOD_NAME = "CelsiusToFahrenheit";
private final String NAMESPACE = "http://tempuri.org/";
private 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.tv);
SoapObject Request = new SoapObject(NAMESPACE, METHOD_NAME);
Request.addProperty("celsius", "32");
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();
tv.setText("status:" + response);
} catch (Exception e) {
e.printStackTrace();
}
}
}
我正在使用来自这个 url 的网络服务
http://www.w3schools.com/webservices/tempconvert.asmx