gpt4 book ai didi

c# - 如何从 Web 服务获取 XML?

转载 作者:行者123 更新时间:2023-11-30 22:01:56 24 4
gpt4 key购买 nike

我正在尝试访问位于 this link 的 Web 服务

如果您调用该方法,您将获得响应。

现在我想从我的 asp.net 应用程序调用 GetCitiesByCountry 方法并只将城市加载到下拉列表中,我编写了以下代码

protected void Page_Load(object sender, EventArgs e)
{
weather.GlobalWeatherSoapClient wet = new weather.GlobalWeatherSoapClient();
DataSet ds = new DataSet(wet.GetCitiesByCountry("United Kingdom"));
ds.GetXml();
DropDownList1.DataTextField = "City";
DropDownList1.DataValueField = "City";
DropDownList1.DataSource = ds;
DropDownList1.DataBind();
}

但我收到以下错误:

“/”应用程序中的服务器错误。

IListSource 不包含任何数据源。

描述:在执行当前网络请求期间发生未处理的异常。请查看堆栈跟踪以获取有关错误及其在代码中的来源的更多信息。

异常详细信息:System.Web.HttpException:IListSource 不包含任何数据源。

Source Error:     

Line 23: DropDownList1.DataValueField = "City";
Line 24: DropDownList1.DataSource = ds;
Line 25: DropDownList1.DataBind();

源文件:c:\Users\Rafi\Documents\Visual Studio 2013\Projects\WebSite4\demo1\main.aspx.cs 行:25


如有任何帮助,我们将不胜感激。

最佳答案

你使用了错误的 DataSet 函数

DataSet ds = new DataSet();
ds.ReadXml(new StringReader(wet.GetCitiesByCountry("United Kingdom")));

参见 Msdn

关于c# - 如何从 Web 服务获取 XML?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27307708/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com