我正在尝试使用此Web服务:http://www.ezzylearning.com/services/CountryInformationService.asmx使用KSoap。
当我调用没有参数的Web方法(例如:GetContinents)时,它可以正常工作。当我尝试使用带参数的一个时,它总是返回空数据。
这是我的Activity类(用于测试目的):
public class MyTestActivity extends Activity
{
private static final String NAMESPACE = "http://www.ezzylearning.com/services/";
private static final String URL = "http://www.ezzylearning.com/services/CountryInformationService.asmx?WSDL";
private static final String ACTION_GET_COUNTRIES_BY_CONTINENT = "http://www.ezzylearning.com/services/CountryInformationService.asmx/GetCountriesByContinent";
private static final String METHOD_GET_COUNTRIES_BY_CONTINENT = "GetCountriesByContinent";
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.fourth);
String property = "continentCode";
String value = "AS";
new GetCountriesByContinentTask().execute(URL, NAMESPACE, ACTION_GET_COUNTRIES_BY_CONTINENT, METHOD_GET_COUNTRIES_BY_CONTINENT, property, value);
}
// Implementation of AsyncTask used get the countries by continent.
private class GetCountriesByContinentTask extends AsyncTask<String, Void, String>
{
@Override
protected void onPreExecute()
{
}
@Override
protected String doInBackground(String... params)
{
String result = "Testing...";
String url = params[0];
String namespace = params[1];
String action = params[2];
String method = params[3];
String property = params[4];
String value = params[5];
List<PropertyInfo> propertyList = new ArrayList<PropertyInfo>();
//Use this to add parameters
PropertyInfo pi = new PropertyInfo();
pi.setName(property);
pi.setValue(value);
pi.setType(String.class);
propertyList.add(pi);
try
{
MySoapHandler soapHandler = new MySoapHandler();
SoapObject soapRresult = soapHandler.soapCall(url, namespace, action, method, propertyList);
if (soapRresult != null)
{
System.out.println("RESULT: " + soapRresult.toString()); // THE DATA SET IS ALWAYS EMPTY
}
}
catch (Exception ex)
{
System.out.println("Exception: " + ex.getMessage());
ex.printStackTrace();
}
return result;
}
@Override
protected void onPostExecute(String result)
{
}
}
}
我的班级用于呼叫网络服务:
public class MySoapHandler
{
public
public SoapObject soapCall(String url,
String namespace,
String action,
String method,
List<PropertyInfo> propertyInfoList)
throws IOException, XmlPullParserException
{
//Initialize soap request
SoapObject request = new SoapObject(namespace, method);
//Add parameters
if(propertyInfoList != null)
{
for(PropertyInfo pi: propertyInfoList)
{
request.addProperty(pi);
}
}
//Declare the version of the SOAP request
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.setOutputSoapObject(request);
envelope.dotNet = true;
//Call the webservice
HttpTransportSE transport = new HttpTransportSE(url);
transport.call(action, envelope);
//Return the SoapResult from the envelope body.
return (SoapObject)envelope.bodyIn;
}
}
知道我做错了什么?
我还尝试将 envelope.bodyIn 更改为 envelope.getResponse(),但数据集仍为空。
谢谢。