我在调用 web 服务时遇到问题,我在服务器中有一个 .NET web 服务,我在 Android 中使用 KSOAP(ksoap2-android-assembly-2.5.7-jar-with-dependencies.jar)。在运行程序时,我得到了一个名为“org.ksoap2.serialization.SoapPrimitive”的运行时异常。
我尝试使用我在链接中阅读的选项:如何使用 KSOAP2 从 Android 调用 .NET Webservice?和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服务并且可以工作!问题是当我发送参数时......我猜:/