Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/wcf/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用WCF数据服务更新数据库中的记录_Wcf_Wcf Data Services - Fatal编程技术网

使用WCF数据服务更新数据库中的记录

使用WCF数据服务更新数据库中的记录,wcf,wcf-data-services,Wcf,Wcf Data Services,我正在尝试使用WCF数据服务,但我有点困惑,基于键字段值更新记录的错误在哪里。 我的简化方法不起作用: MydbEntities context = new MydbEntities(new Uri("http://localhost:53051/Services/MydbService.svc")); MyEntity avt = context.MyTable.Where(p => p.EntID == "val1").FirstOrDefault(); avt.FieldToE

我正在尝试使用WCF数据服务,但我有点困惑,基于键字段值更新记录的错误在哪里。
我的简化方法不起作用:

 MydbEntities context = new MydbEntities(new Uri("http://localhost:53051/Services/MydbService.svc"));
 MyEntity avt = context.MyTable.Where(p => p.EntID == "val1").FirstOrDefault();
 avt.FieldToEdit = 1;
 context.UpdateObject(avt);
 context.BeginSaveChanges(OnChangesSaved, context);
 ...
 private void OnChangesSaved(IAsyncResult result)
 {            
     MessageBox.Show("seems ok");//I'm getting this message, but, in fact, data in db remains unchanged
 }

请告诉我,我哪里错了?

在OnChangesSaved处理程序中,您需要调用
context.EndSaveChanges(result)


这有一些示例代码说明了整个过程。

我找到了问题的原因。这很简单(我觉得自己像个白痴),服务初始值设定项中没有设置写入访问权限。有以下情况:

public static void InitializeService(DataServiceConfiguration config)
{
    config.SetEntitySetAccessRule("*", EntitySetRights.AllRead);
      ...
}
我把它改成:

config.SetEntitySetAccessRule("*", EntitySetRights.All);
一切如期开始。
当然,我设置的这种广泛的访问规则只是为了测试目的。以后应该限制。

谢谢。我试过了,但问题是,当尝试调用它时,我遇到了一个运行时错误:
处理此请求时出错。