嗨,我试图将从 aspx webservice 返回的项目数组传递给 android 中的微调器。但它返回null。我想知道我做错了什么。我之前确实尝试过返回一组字符串,并且它适用于相同的连接,任何帮助将不胜感激。
我的安卓代码如下:
package com.example.fp1_webservicedropdown;
import android.R.string;
import android.app.Activity;
import android.os.Bundle;
import android.widget.ArrayAdapter;
import android.widget.Spinner;
import android.widget.TextView;
import org.ksoap2.*;
import org.ksoap2.serialization.SoapObject;
import org.ksoap2.serialization.SoapPrimitive;
import org.ksoap2.serialization.SoapSerializationEnvelope;
import org.ksoap2.transport.*;
public class MainActivity extends Activity {
TextView result;
Spinner spinnerC;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
spinnerC=(Spinner) findViewById(R.id.spinner1);
result = (TextView) findViewById(R.id.textView2);
final String NAMESPACE = "http://sample.com/";
final String METHOD_NAME = "GetCustomerList";
final String SOAP_ACTION = "http://sample.com/GetCustomerList";
final String URL = "http://mylocalip/HelloWorldNew/Service1.asmx";
SoapObject Request = new SoapObject(NAMESPACE, METHOD_NAME);
//Request.addProperty("a", "32");
//Request.addProperty("b", "12");
SoapSerializationEnvelope soapEnvelope = new SoapSerializationEnvelope(
SoapEnvelope.VER11);
soapEnvelope.dotNet = true;
soapEnvelope.setOutputSoapObject(Request);
AndroidHttpTransport aht = new AndroidHttpTransport(URL);
try {
aht.call(SOAP_ACTION, soapEnvelope);
SoapPrimitive resultString = (SoapPrimitive) soapEnvelope
.getResponse();
result.setText("The web service returned "
+ resultString.toString());
//---------- result To Spinner Code -----------------------//
String[] toSpinner = new String[]{resultString.toString()};
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
android.R.layout.simple_spinner_item, toSpinner );
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spinnerC.setAdapter(adapter);
//---------- result To Spinner Code ends here -----------------------//
} catch (Exception e) {
e.printStackTrace();
}
}
}
我的网络服务代码如下:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Collections;
namespace HelloWorldNew
{
/// <summary>
/// Summary description for Service1
/// </summary>
[WebService(Namespace = "http://sample.com/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.ComponentModel.ToolboxItem(false)]
// To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line.
// [System.Web.Script.Services.ScriptService]
public class Service1 : System.Web.Services.WebService
{
[WebMethod]
public ArrayList GetCustomerList()
{
ArrayList list = new ArrayList();
list.Add("Shean");
list.Add("Yo");
return list;
}
}
}