2010-10-03 29 views
0

下面的代碼會拋出一個異常,我不知道哪裏出了問題,請問有誰可以對此進行說明?在SilverLight組件中調用WCF

RestAPIDataContext ctx = GetContext();    
var songsQuery = (from item in ctx.Songs 
            where item.Artist.Title == "George Michael" 
            select item) as DataServiceQuery<SongsItem>; 
        songsQuery.BeginExecute(
         (IAsyncResult asyncResult) => Dispatcher.BeginInvoke(() => 
                       { 
                        songsList.ItemsSource = songsQuery.EndExecute(asyncResult); 
                       }), songsQuery 
         ); 
private static RestAPIDataContext GetContext() 
     { 
      RestAPIDataContext ctx = 
       new RestAPIDataContext(
       new Uri("http://win-oirj50igics/restapi/_vti_bin/ListData.svc")); 
      return ctx; 
     } 

System.Data.Services.Client.DataServiceQueryException:處理此請求時發生錯誤。 ---> System.InvalidOperationException:保存更改時發生錯誤。詳情請參閱內部例外。 ---> System.Data.Services.Client.DataServiceClientException: 請求版本'1.0'對響應太低。最低的支持版本是'2.0'。 --- System.Data.Services.Client.BaseAsyncResult.EndExecute [T](Object source,String method,IAsyncResult asyncResult) 處的內部異常堆棧跟蹤--- 結束。 QueryAsyncResult.EndExecute [TElement](Object source,IAsyncResult asyncResult) --- End of internal exception stack trace --- at System.Data.Services.Client.QueryAsyncResult.EndExecute [TElement](Object source,IAsyncResult asyncResult) 在System.Data.Services.Client.DataServiceQuery`1.EndExecute(IAsyncResult asyncResult) at SLRest.MainPage。 <> c_ DisplayClass3。 <> c _DisplayClass5.b__1()

回答

1

來自調用堆棧,它看起來像您使用的是ADO.Net數據服務框架。您可以嘗試使用此更新程序link或將您的調用者應用程序的目標框架更改爲4.0。

檢查這個link的細節

+0

感謝隊友,你的解決方案work.But礦井沒有控制檯應用程序,它是Silverlight的app.So我改變從3.0我的Silverlight應用程序的版本4.0,現在工作得很好。 – Ybbest 2010-10-03 04:23:57