我在 Tomcat7 服务器上部署了一个简单的 java web 服务。我已将 Axis2 用作肥皂引擎。(Web 服务和 WSDL 没问题)这是我用于 Web 服务的代码
public class TestWs {
public String sayHello(){
return "Hello Grant";
}
}
我已经从 Android 2.2 访问了这个网络服务。完全没问题。但是这个程序不适用于 Android 4.0.3 我的 Android 程序的代码
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.widget.TextView;
import android.app.Activity;
import android.os.Bundle;
public class AndroidWSClientActivity extends Activity {
private static final String SOAP_ACTION = "http://ws.android4.com/";
private static final String METHOD_NAME = "sayHello";
private static final String NAMESPACE = "http://ws.android4.com/sayHello/";
private static final String URL = "http://175.157.45.91:8085/ForAndroid4/services/TestWs?wsdl";
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
SoapSerializationEnvelope envelope = new
SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.setOutputSoapObject(request);
HttpTransportSE ht = new HttpTransportSE(URL);
try {
ht.call(SOAP_ACTION, envelope);
SoapPrimitive response = (SoapPrimitive)envelope.getResponse();
String str = response.toString();
TextView result;
result = (TextView)findViewById(R.id.textView1);
result.setText(str);
} catch (Exception e) {
e.printStackTrace();
TextView result;
result = (TextView)findViewById(R.id.textView1);
result.setText("Error!");
}
}
}
程序正确安装在模拟器上。但模拟器显示来自 catch 块的消息集。错误是什么???我该如何纠正它?谢谢!