我想连接到基于WSDL的Web服务,只需在TextView中显示String响应
代码:
package com.example.wsdlclient;
import org.ksoap2.SoapEnvelope;
import org.ksoap2.serialization.SoapObject;
import org.ksoap2.serialization.SoapPrimitive;
import org.ksoap2.serialization.SoapSerializationEnvelope;
import org.ksoap2.transport.HttpTransportSE;
import android.util.Log;
import android.widget.TextView;
import android.app.Activity;
import android.os.Bundle;
public class MainActivity extends Activity {
private static final String SOAP_ACTION = "http://www.taryatechnologies.com/ws/getCountry";
private static final String METHOD_NAME = "getCountry";
private static final String NAMESPACE = "http://www.taryatechnologies.com/ws";
private static final String URL = "http://tarya.co.uk/ws/Ip2countryws.asmx?WSDL";
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Thread networkThread = new Thread() {
@Override
public void run() {
try {
SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
request.addProperty("arg0", "49.248.145.220");
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
SoapEnvelope.VER11);
envelope.setOutputSoapObject(request);
HttpTransportSE ht = new HttpTransportSE(URL);
ht.call(SOAP_ACTION, envelope);
final SoapPrimitive response = (SoapPrimitive) envelope.getResponse();
final String str = response.toString();
runOnUiThread(new Runnable() {
public void run() {
TextView result;
result = (TextView) findViewById(R.id.textView1);
result.setText(str);
}
});
} catch (Exception e) {
e.printStackTrace();
}
}
};
networkThread.start();
}
}
该服务应该返回IP所属的国家/地区名称。 我通过请求传递了IP:
request.addProperty(“arg0”,“49.248.145.220”);
也尝试过:
request.addProperty(“ipnumb”,“49.248.145.220”); //因为ipnumb是参数ID。
我得到以下字符串(错误)作为回复:
从字符串“”到“Double”类型的转换无效。
请帮忙。