0

我正在使用以下代码访问网络服务

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 - 故障代码:'soap:Server' 故障字符串:'System.Web.Services.Protocols.SoapException:服务器无法处理请求。---> System.ArgumentNullException:值不能为空。

4

1 回答 1

1

请换行:

envelope.dotNet = "true";

envelope.dotNet = "false";

因为“真”总是向网络服务器发送一个空值,所以设置一个假..

和其他东西..在你的代码中

request.addProperty("Username","myusername");

request.addProperty("Password","pass");

检查客户端和服务器端 Web 服务上的参数名称(用户名、密码)必须相同,这意味着它区分大小写。

希望代码对你有所帮助。

于 2012-04-07T07:36:25.113 回答