【发布时间】:2014-06-06 23:30:16
【问题描述】:
这是我第一次使用 Web 服务,我有点迷茫。 我成功调用了这些函数,但我只能从中获得一个值 服务。我读到最简单的方法是读取 xml 或创建对象 然后调用它们的值。目前我使用返回所需的函数 值,但我需要给他们打电话 3 次才能获得所有数据,女巫是浪费时间 和资源。我尝试使用 URL 调用服务并将其用作网站 或让服务以相同的方式工作而不导入程序。 问题是我找不到将值传递到 url 的方法,因为 我只得到空白页。从服务中获取我的数据的最快方法是什么? 如果城市有效,我需要城市名称、温度和旗帜。我需要通过拉链 服务代码。
谢谢。
我当前的代码
wetther.Weather wether = 新wetther.Weather();
string farenhait = wether.GetCityWeatherByZIP(zip).Temperature;
string city = wether.GetCityWeatherByZIP(zip).City;
bool correct = wether.GetCityWeatherByZIP(zip).Success;
我试过了
// Retrieve XML document
XmlTextReader reader = new XmlTextReader("http://xml.weather.yahoo.com/forecastrss?p=94704");
// Skip non-significant whitespace
reader.WhitespaceHandling = WhitespaceHandling.Significant;
// Read nodes one at a time
while (reader.Read())
{
// Print out info on node
Console.WriteLine("{0}: {1}", reader.NodeType.ToString(), reader.Name);
}
这个适用于雅虎页面,但不适用于我的页面。
我需要使用这个网络服务 -> http://wsf.cdyne.com/WeatherWS/Weather.asmx
【问题讨论】:
-
您正在使用 C# 中的 Web 服务,对吗?为什么不添加网络服务参考How to: Add a Reference to a Web Service
-
@Anuraj 实际上目前我正在这样做。我只是不知道如何获取xml。我只能获得每个连接的值。
标签: c# xml web-services