我使用以下代码访问webserivce
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:Server无法处理请求。 ---&GT; System.ArgumentNullException:值不能为null。
答案 0 :(得分:1)
请更改行:
envelope.dotNet = "true";
到
envelope.dotNet = "false";
因为“true”总是向webserver发送一个空值,所以设置一个false ..
和你的代码中的其他东西
request.addProperty("Username","myusername");
request.addProperty("Password","pass");
检查客户端和服务器端webservice上的参数名称(用户名,密码)必须相同,这意味着它区分大小写。
我希望代码可以帮助你。