由於Windows Phone 7是基於Silverlight的,因此需要異步,因此在上下文中沒有SaveChanges
方法,而是使用BeginSaveChanges
和EndSaveChanges
方法對。你可以打電話給他們,像這樣:
private void SaveChanges_Click(object sender, RoutedEventArgs e)
{
// Start the saving changes operation.
svcContext.BeginSaveChanges(SaveChangesOptions.Batch,
OnChangesSaved, svcContext);
}
private void OnChangesSaved(IAsyncResult result)
{
// Use the Dispatcher to ensure that the
// asynchronous call returns in the correct thread.
Dispatcher.BeginInvoke(() =>
{
svcContext = result.AsyncState as NorthwindEntities;
try
{
// Complete the save changes operation and display the response.
WriteOperationResponse(svcContext.EndSaveChanges(result));
}
catch (DataServiceRequestException ex)
{
// Display the error from the response.
WriteOperationResponse(ex.Response);
}
catch (InvalidOperationException ex)
{
messageTextBlock.Text = ex.Message;
}
finally
{
// Set the order in the grid.
ordersGrid.SelectedItem = currentOrder;
}
}
);
}
這樣品是來自http://msdn.microsoft.com/en-us/library/gg521146(VS.92).aspx。
如果我對你的問題的理解是正確的,這對我來說有點令人驚訝。在「添加服務引用」(ASR)時間,我認爲客戶端不會進行任何特殊檢查來查看服務是否爲讀/寫(它實際上需要POST服務來測試)。因此理論上它應該始終生成SaveChanges()方法,而不管實現IUpdatable的服務如何。你能在這裏給我們更多的細節嗎?您正在使用哪些版本的Visual Studio,Windows Phone SDK和WCF數據服務?您是如何生成服務參考的? – 2012-08-12 15:45:02
我正在使用VS2010 Ultimate,Windows Phone SDK 7.1,不確定我使用的是哪個版本的WCF數據服務。我將如何發現?我添加WCf服務的方式是右鍵單擊Referecnces,clicekd添加服務引用,輸入到我的WCF數據服務.scv url中,鍵入命名空間並單擊確定。然後它爲我創建了datasvcmap和.cs文件。 – 2012-08-12 19:02:15
對不起,剛剛註冊的Windows Phone 7位 - 這些方法在WP7上是異步的,所以它們遵循「BeginSaveChanges」和「EndSaveChanges」的通用命名約定。請參閱下面的示例。 – 2012-08-12 23:44:39