2013-11-26 76 views
0

我看到了一個從MCWebServiceSoapClient調用的Web服務的方法。在Windows Phone中調用webservice和WCF?

//getting the different points for the map when checkbox is checked 
private void polyc_Checked(object sender, RoutedEventArgs e) 
{ 
    testingwcf.MCWebServiceSoapClient ob = new TestMap.testingwcf.MCWebServiceSoapClient(); 
    ob.getPolytechnicPointsAsync(); 
    ob.getPolytechnicPointsCompleted += new EventHandler<testingwcf.getPolytechnicPointsCompletedEventArgs>(ob_getPolyPointsCompleted); 
} 

但是我正在執行的是WCF。如何將此方法轉換爲WCF?我的WCF在這裏http://kailun92wcf.cloudapp.net/Service1.svc。是否可以從WCF調用Windows Phone ersi地圖?要繪製點?

回答

1

您想從WP應用程序中使用WCF服務嗎?首先,通過visual studio生成客戶端代理,右鍵單擊「引用」,選擇「添加服務引用」,選擇「開始」按鈕,如果該向導在線,應該發現你的服務。

選擇高級按鈕,並在代碼下面選擇

enter image description here

enter image description here

的選項後面,掛鉤到一個點擊事件,

private void LoadWebService(object sender, RoutedEventArgs e) 
    { 
     var service = new Service1Client(); 

     service.getRecommendPlaceAsync(new getRecommendPlaceRequest { activityId = 1}); //Provide your id here 

     service.getRecommendPlaceCompleted += new EventHandler<MyCloundService.getRecommendPlaceCompletedEventArgs>(RecommendedPlaceRequestComplete); 
    } 

    void RecommendedPlaceRequestComplete(object sender, MyCloundService.getRecommendPlaceCompletedEventArgs e) 
    { 
     if (e.Error == null) 
     { 
      var result = String.Join(",", (from place in e.Result.getRecommendPlaceResult select place.Name).ToArray()); 

      MessageBox.Show(result); 
     } 
     else 
     { 
      MessageBox.Show("An error occured: " + e.Error.Message); 
     } 
    } 

參見教程here

+0

真誠地感謝您=) – NoobieNeedHelp