设为首页 - 加入收藏 ASP站长网(Aspzz.Cn)- 科技、建站、经验、云计算、5G、大数据,站长网!
热搜: 数据 创业者 手机
当前位置: 首页 > 服务器 > 系统 > 正文

windows-phone-7 – 如何在Windows Phone 7中调用webservice方法

发布时间:2021-02-05 00:32 所属栏目:52 来源:网络整理
导读:为了连接到webservices,我编写了以下代码. WebClient wc = new WebClient();wc.DownloadStringAsync(new Uri("http://www.Webservices.asmx"));wc.DownloadStringCompleted += new DownloadStringCompletedEventHandler(wc_DownloadStringCompleted);void wc

为了连接到webservices,我编写了以下代码.

WebClient wc = new WebClient();
wc.DownloadStringAsync(new Uri("http://www.Webservices.asmx"));
wc.DownloadStringCompleted += new DownloadStringCompletedEventHandler(wc_DownloadStringCompleted);

void wc_DownloadStringCompleted(object sender,DownloadStringCompletedEventArgs e)
{
    Debug.WriteLine("Web service says: " + e.Result);
    using (var reader = new StringReader(e.Result))
    {
        String str = reader.ReadToEnd();
    }
}

通过使用上面的代码获取字符串结果.但我想在HTMLVisulaizer中获得结果然后我知道有什么方法有webservice.then我可以轻松访问特定的方法.
请告诉我如何在Windows Phone 7中调用Web服务方法?在webservice中我有5个webmethods.how来获取它以及如何调用特殊webmenthod.

请提前告诉我.

解决方法

@Jason James

第一步:

你必须添加参考服务,就像杰森詹姆斯有非常详细的说明.

第2步 :

您可以在Functions Apps中打开App.xaml.cs

public Apps()
{
    // Global handler for uncaught exceptions. 
            UnhandledException += Application_UnhandledException;

            // Show graphics profiling information while debugging.
            if (System.Diagnostics.Debugger.IsAttached)
            {
                // Display the current frame rate counters.
                Application.Current.Host.Settings.EnableFrameRateCounter = true;

                // Show the areas of the app that are being redrawn in each frame.
                //Application.Current.Host.Settings.EnableRedrawRegions = true;

                // Enable non-production analysis visualization mode,// which shows areas of a page that are being GPU accelerated with a colored overlay.
                //Application.Current.Host.Settings.EnableCacheVisualization = true;
             }
           // You can declare objects here that you will use
           //Examlpe: NameservicesReferent.(Function that returns services) = new NameservicesReferent.(Function that returns services)();

Ws_Function = new Nameservices.ServiceSoapClient();

}

第3步:

在Mainpage.xaml.cs中

GlobalVariables.Ws_advertise.getLinkAdvertiseIndexCompleted += new EventHandler<advertise.getLinkAdvertiseIndexCompletedEventArgs>(Ws_advertise_getLinkAdvertiseIndexCompleted);
GlobalVariables.***NameWedservise***.getLinkAdvertiseIndexAsync("**parameters to be passed**");

第4步:

void Ws_advertise_getLinkAdvertiseIndexCompleted(object sender,advertise.getLinkAdvertiseIndexCompletedEventArgs e)
        {
             //function returns the results to you,the example here is an array
           string[] array = null;
           try

           {
              array = e.result;
              if(array != null)

           }
           cath(exception ex)
           {

           }
           finally
           {
             array = null;
GlobalVariables.Ws_advertise.getLinkAdvertiseIndexCompleted -= new EventHandler<advertise.getLinkAdvertiseIndexCompletedEventArgs>(Ws_advertise_getLinkAdvertiseIndexCompleted);
           }
         }

(编辑:ASP站长网)

    网友评论
    推荐文章
      热点阅读