在Android中访问javaweb服务
使用ksoap2从Android应用程序调用Java web服务时出现问题。我的web服务类有一个私有变量,我使用getter和setter更新该变量。我想通过使用get方法获取Android应用程序的值。我该怎么做?请帮帮我!我是编程新手 我的web服务类:在Android中访问javaweb服务,java,android,ksoap2,Java,Android,Ksoap2,使用ksoap2从Android应用程序调用Java web服务时出现问题。我的web服务类有一个私有变量,我使用getter和setter更新该变量。我想通过使用get方法获取Android应用程序的值。我该怎么做?请帮帮我!我是编程新手 我的web服务类: public class Customer { private String customerName; public String getCustomerName() { return customer
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 android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.widget.TextView;
import android.app.Activity;
import android.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();
}
}
}
我认为您的URL必须是:
private static final String URL = "http://175.157.141.120:8085/TestVTwo/services/Customer";
好的,我意识到
getCustomerName
返回一个字符串,因此您必须执行以下操作:
SoapObject response = (SoapObject)envelope.getResponse();
TextView tv = new TextView(this);
tv.setText("Message :" + response.toString());
setContentView(tv);
如果仍然存在错误,请发布异常堆栈跟踪。确定!!我通过使用MySQL数据库解决了这个问题&创建一个Android客户端来访问MySQL数据库 请同时提及您的请求和响应格式。因为ksoap不支持某些请求和响应格式。在我们提供帮助之前,您应该先看看常见问题解答。您必须提供更多的上下文。完全不清楚你的问题是什么。请发布一些代码(相关部分)和/或一些异常堆栈跟踪。诸如此类-诸如此类-你做了什么,发布代码-诸如此类-诸如此类什么不起作用?有例外吗?没有,这不算例外。但是android应用程序没有显示demo java类设置的值。它只显示默认消息。我尝试将响应值转换为字符串,但这也无法解决问题。。。。。我认为set方法的问题在于它不能正确地更新变量。当我使用像“private String name=“Sean”;“这样的私有变量时,android客户端会显示正确的值。我想知道如何正确更新服务器中的私有值。谢谢你们在我的问题上花费时间。