次のコードを使用してWebサービスにアクセスしています
public SoapObject getWeather() throws Exception
{
SoapObject request = new SoapObject("http://www.freewebservicesx.com", "GetCurrentGoldPrice");
//request.addProperty("PlaceName", city);
request.addProperty("Username","myusername");
request.addProperty("Password","pass");
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.setOutputSoapObject(request);
// It seems that it is a .NET Web service because it doesn't work without next line
envelope.dotNet = true;
HttpTransportSE transport = new HttpTransportSE("http://www.freewebservicesx.com/GetGoldPrice.asmx");
transport.call("http://freewebservicesx.com/GetCurrentGoldPrice", envelope);
return (SoapObject) envelope.getResponse();
}
public List<CharSequence> getWeatherForecast()
{
SoapObject obj = null;
try {
obj = getWeather();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
//error is being thrown here
Log.e("error",e.getMessage());
}
SoapObject details = (SoapObject) obj.getProperty("GetCurrentGoldPriceResult");
List<CharSequence> list = new ArrayList<CharSequence>(details.getPropertyCount());
for (int i = 0; i < details.getPropertyCount(); i++) {
Object property = details.getProperty(i);
if (property instanceof SoapObject) {
SoapObject weather = (SoapObject) property;
String day = weather.getProperty("string").toString();
String min = weather.getProperty("string").toString();
//String max = weather.getProperty("MaxTemperatureF").toString();
Log.v("ts is whait ai am ",day);
list.add(day + " :: " + min);
}
}
return list;
}
http://www.freewebservicesx.com/GetGoldPrice.asmx?op=GetCurrentGoldPriceには、サービスの詳細が含まれています。失敗したバインダー トランザクション エラーが発生します。
04-07 11:10:01.405: W/System.err(651): SoapFault - faultcode: 'soap:Server' faultstring: 'System.Web.Services.Protocols.SoapException: サーバーは要求を処理できませんでした。---> System.ArgumentNullException: 値を null にすることはできません。