由于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