KSOAP:“org.ksoap2.serialization.SoapPrimitive”异常问题
我在调用 Web 服务时遇到问题,我的服务器中有一个 .NET Web 服务,并且我在 Android 中使用 KSOAP(ksoap2-android- assembly-2.5.7-jar-with-dependency.jar)。 运行程序时,我收到一个名为“org.ksoap2.serialization.SoapPrimitive”的运行时异常。
我尝试了在链接中阅读的选项: 如何使用 KSOAP2 从 Android 调用 .NET Web 服务? 和 kSoap2 Android -- Cast Class Exception (SoapObject) 但没有任何帮助我
这是我的代码:
try{
//Conexión a Web Service
SoapObject Solicitud = new SoapObject(NAMESPACE, METODO);
PropertyInfo sector = new PropertyInfo();
sector.setName("sector");
sector.setValue(sectorX.toString());
Solicitud.addProperty(sector);
SoapSerializationEnvelope Envoltorio = new SoapSerializationEnvelope (SoapEnvelope.VER12);
Envoltorio.dotNet = true;
Envoltorio.setOutputSoapObject (Solicitud);
HttpTransportSE TransporteHttp = new HttpTransportSE(URL);
TransporteHttp.call (SOAP_ACTION, Envoltorio);
//Obtencion de datos
SoapObject resultado = (SoapObject)Envoltorio.getResponse();
final String[] testValues = new String[resultado.getPropertyCount()];
final Number[] serie = new Number[resultado.getPropertyCount()];
for(int i= 0; i< resultado.getPropertyCount(); i++){
String x = "";
SoapObject wii = (SoapObject)resultado.getProperty(i);
x += wii.getPropertyAsString(1);
testValues[i] = wii.getPropertyAsString(1);
x.trim();
serie[i]=Integer.parseInt(x);
}
ArrayAdapter<String> adaptador = new ArrayAdapter<String>(this, R.layout.lista_sectores, testValues);
final ListView LstOpciones = (ListView) findViewById(R.id.LstOpciones);
LstOpciones.setAdapter(adaptador);
LstOpciones.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View itemClicked,
int position, long id) {
// TODO Auto-generated method stub
TextView textview = (TextView)itemClicked;
String strText = textview.getText().toString();
seleccion.setText("Seleccionado: " + strText);
} catch (Exception e){
txtMensaje.setText(e.getMessage());
}
其中,sectorX 是我提供给 WS 的字符串参数。
我尝试了不带参数的 Web 服务并且有效! 问题是当我发送参数时......我猜:/
I have a problem while calling the webservice, I have a .NET web service in the server and I am using KSOAP(ksoap2-android-assembly-2.5.7-jar-with-dependencies.jar) in Android.
While running the program I got an runtime Exception named "org.ksoap2.serialization.SoapPrimitive".
I tried with the options that i readed in the link: How to call a .NET Webservice from Android using KSOAP2? and kSoap2 Android -- Cast Class Exception (SoapObject) but nothing help me
This my code:
try{
//Conexión a Web Service
SoapObject Solicitud = new SoapObject(NAMESPACE, METODO);
PropertyInfo sector = new PropertyInfo();
sector.setName("sector");
sector.setValue(sectorX.toString());
Solicitud.addProperty(sector);
SoapSerializationEnvelope Envoltorio = new SoapSerializationEnvelope (SoapEnvelope.VER12);
Envoltorio.dotNet = true;
Envoltorio.setOutputSoapObject (Solicitud);
HttpTransportSE TransporteHttp = new HttpTransportSE(URL);
TransporteHttp.call (SOAP_ACTION, Envoltorio);
//Obtencion de datos
SoapObject resultado = (SoapObject)Envoltorio.getResponse();
final String[] testValues = new String[resultado.getPropertyCount()];
final Number[] serie = new Number[resultado.getPropertyCount()];
for(int i= 0; i< resultado.getPropertyCount(); i++){
String x = "";
SoapObject wii = (SoapObject)resultado.getProperty(i);
x += wii.getPropertyAsString(1);
testValues[i] = wii.getPropertyAsString(1);
x.trim();
serie[i]=Integer.parseInt(x);
}
ArrayAdapter<String> adaptador = new ArrayAdapter<String>(this, R.layout.lista_sectores, testValues);
final ListView LstOpciones = (ListView) findViewById(R.id.LstOpciones);
LstOpciones.setAdapter(adaptador);
LstOpciones.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View itemClicked,
int position, long id) {
// TODO Auto-generated method stub
TextView textview = (TextView)itemClicked;
String strText = textview.getText().toString();
seleccion.setText("Seleccionado: " + strText);
} catch (Exception e){
txtMensaje.setText(e.getMessage());
}
Where sectorX it's a String parameter that I give to WS.
I tried the Web service without parameters and works!
The problem is when I send parameter... I guess :/
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这个名字也不例外。您可能会遇到类转换异常。如果您进行调试,您可能会发现您的响应是一个 SoapObject。那么你可以使用 getProperty 或 getAttribute 或其他任何东西。如果您设置断点,您将能够浏览对象图并手动组装解析代码..
也许将堆栈跟踪发布在某处..
There is no exception of that name. You probably get a class cast exception. If you debug you will probably find that your response is a SoapObject. So then you use getProperty or getAttribute or whatever on it. IF you set a break point you will be able to browse the object graph and assemble your parse code manually ..
Maybe post the stacktrace somewhere..
您可以尝试仅使用“Object”而不是使用“SoapObject”。这对我有用。希望有帮助。
You can try using only 'Object' instead of using 'SoapObject'. It works for me. Hope it helps.