在Android中访问javaweb服务
使用ksoap2从Android应用程序调用Java web服务时出现问题。我的web服务类有一个私有变量,我使用getters&;设置器来更新该变量。我想通过使用get方法获取Android应用程序的值。我该怎么做?请帮帮我!我是编程新手
我的web服务类:
public class Customer {
private String customerName;
public String getCustomerName() {
return customerName;
}
public void setCustomerName(String customerName) {
this.customerName = customerName;
}
我使用了一个演示类来设置customer name值。但是,当使用模拟器运行应用程序时,它不会给出应有的值。它只显示打开的默认消息
package com.testversiontwo.ws;
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 安卓.app.Activity;
import 安卓.os.Bundle;
import 安卓.util.Log;
import 安卓.widget.TextView;
import 安卓.app.Activity;
import 安卓.os.Bundle;
public class TestVTwoClientActivity extends Activity {
private static final String SOAP_ACTION = "http://ws.customer.com";
private static final String METHOD_NAME = "getCustomerName";
private static final String NAMESPACE = "http://ws.customer.com/getCustomerName/";
private static final String URL = "http://175.157.141.120:8085/TestVTwo/services/Customer?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();
Log.i("myApp", response.toString());
TextView tv = new TextView(this);
tv.setText("Message :"+response);
setContentView(tv);
} catch (Exception e) {
e.printStackTrace();
}
}
}
# 1 楼答案
好的,我意识到
getCustomerName
返回一个字符串,所以您必须执行以下操作:如果仍然存在错误,请发布异常堆栈跟踪
# 2 楼答案
好的!!我已经通过使用MySQL数据库解决了这个问题;创建一个Android客户端来访问MySQL数据库
# 3 楼答案
我认为你的URL必须是: