【问题标题】:Connecting to a web service with SilverLight使用 SilverLight 连接到 Web 服务
【发布时间】:2012-04-18 04:15:02
【问题描述】:

我一直在网上寻找一种通过 silverlight 应用程序调用 Web 服务的简单方法,但无法决定如何去做。连接到这个网站的最简单方法是什么:http://wsf.cdyne.com/WeatherWS/Weather.asmx 并返回一个带有指定邮政编码的 xml(我已经使用 AJAX 完成了这项工作,我只是想尝试使用 silverlight 作为替代方法让它工作)。非常感谢任何帮助!

谢谢!

【问题讨论】:

    标签: silverlight-4.0


    【解决方案1】:

    嗯.. 就是这么简单。在您的 Silverligt 项目中,单击“Reference”,选择“Add Service Reference..”并添加气象服务的 wsdl (http://wsf.cdyne.com/WeatherWS/Weather.asmx?WSDL)。 Visual Studio 11 Beta 使用basicHttpBinding 生成 WCF 代理。并将其用作任何服务。

    UODATE:添加下一个引用

    using SilverlightApplication1.ServiceReference1;
    

    以及实施。

            public MainPage()
            {
                InitializeComponent();
    
                var weather = new WeatherSoapClient();
                weather.GetWeatherInformationCompleted
                    += new EventHandler<GetWeatherInformationCompletedEventArgs>(OnGetWeatherInformationCompleted);
                weather.GetWeatherInformationAsync();
            }
    
            private void OnGetWeatherInformationCompleted(object sender, GetWeatherInformationCompletedEventArgs e)
            {
                // Get data from e.Result
            }
    

    在我看来,您应该阅读一些有关 Web 服务和 WCF 的内容。

    【讨论】:

    • 我已经完成了,但我不确定如何拨打电话以及如何返回信息。
    • 我是否将 C# 代码放在服务器端?以及如何传递参数?非常感谢!
    • 如果是你的服务器,你可以。您可以为当前的服务实现传递邮政编码。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-04-02
    • 2016-03-26
    • 1970-01-01
    相关资源
    最近更新 更多