将有效的端点名称传递给服务客户端构造函数

时间:2017-09-14 12:25:13

标签: c# wcf

我尝试使用网络服务进行天气

else if (category == "Favorite") {
  for (var i = this.companies.length - 1; i >= 0; i--) {
    this.storage.get(this.companies[i].CompanyName).then(val => {
      if (val == "true"){
        this.companyForFlyers.push(this.companies[i])
      }
    });
  }
  return;
}

我制作控制台应用程序并尝试使用此服务。首先,我添加引用并命名引用http://www.webservicex.com/globalweather.asmx?WSDL 并写下代码

WeatherService

但它给了我一个例外

Console.WriteLine("Now we get weather, please wait .......");

            WeatherService.GlobalWeatherSoapClient w = new WeatherService.GlobalWeatherSoapClient();
            Console.WriteLine(w.GetWeather("Lahore","Pakistan"));

我正在学习网络服务,并且不知道为什么会这样。任何人帮助我这是非常有利的。提前谢谢。

1 个答案:

答案 0 :(得分:1)

打开app.config,找到需要的,然后将其名称传递给GlobalWeatherSoapClient(此处): 在您的app.config中应该设置如下:

      <endpoint address="http://www.webservicex.com/globalweather.asmx"
    binding="basicHttpBinding" bindingConfiguration="GlobalWeatherSoap"
    contract="WeatherService.GlobalWeatherSoap" name="GlobalWeatherSoap" />

获取名称并将其传递给客户:

WeatherService.GlobalWeatherSoapClient w = new WeatherService.GlobalWeatherSoapClient("GlobalWeatherSoap");