locked
Problems with SaveChanges() RRS feed

  • Question

  • I am accessing a Data Services service using a WinForms client.

    I have no problems in bringing back data within this app. However, when I try to call SaveChanges I get a forbidden exception (see below).

    I have tried hosting the Data Service it in IIS and through VS Hosting Process. I have modified the Web.Config to include, additional HTTP verbs. I have changed IIS to include all HTTP verbs.

    Any help would be greatly appreciated.

    Kev.

    WinForms UI Code:

           private ServiceReference1.ModelEntities1 _entSvc = new ServiceReference1.ModelEntities1(new Uri("http://localhost/DSWebSite/DataService.svc/"));  
     
            public Form1()  
            {  
                InitializeComponent();  
      // Having these set or not seems to make no difference   
                _entSvc.Credentials = System.Net.CredentialCache.DefaultNetworkCredentials;  
                _entSvc.UsePostTunneling = true;  
                RenderForm();  
            }  
     
            public void RenderForm()  
            {  
     
                gridControlProviders.DataSource = _entSvc.LocalProviders.ToArray<LocalProviders>();  
                gridControlProviders.RefreshDataSource();  
     
            }  
     
            private void barButtonItem1_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)  
            {  
                _entSvc.SaveChanges();  
            }  
     
            private void gridViewProviders_BeforeLeaveRow(object sender, DevExpress.XtraGrid.Views.Base.RowAllowEventArgs e)  
            {  
                LocalProviders localProvider = (LocalProviders) gridViewProviders.GetRow(e.RowHandle);  
                _entSvc.UpdateObject(localProvider);              
            }  
     
        }  
     
     
     

    Exception:

    System.Data.Services.Client.DataServiceRequestException was unhandled
      Message="An error occurred while processing this request."
      Source="System.Data.Services.Client"
      StackTrace:
           at System.Data.Services.Client.DataServiceContext.SaveAsyncResult.HandleBatchResponse()
           at System.Data.Services.Client.DataServiceContext.SaveAsyncResult.EndRequest()
           at System.Data.Services.Client.DataServiceContext.SaveChanges(SaveChangesOptions options)
           at System.Data.Services.Client.DataServiceContext.SaveChanges()
      . 
     .
     . 
           at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
           at System.Threading.ThreadHelper.ThreadStart()
      InnerException: System.Data.Services.Client.DataServiceClientException
           Message="<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"yes\"?>\r\n<error xmlns=\"\r\n">http://schemas.microsoft.com/ado/2007/08/dataservices/metadata\">\r\n  <code></code>\r\n  <message xml:lang=\"en-GB\">Forbidden</message>\r\n</error>\r\n"
           Source="System.Data.Services.Client"
           StatusCode=403
           StackTrace:
                at System.Data.Services.Client.DataServiceContext.SaveAsyncResult.<HandleBatchResponse>d__1d.MoveNext()
           InnerException:
    Monday, January 19, 2009 9:14 AM

Answers

  • Hi Ken,
     The 403 you are receiving is from the ADO.NET Data Services layer and not the HTTP Layer.
     You will need to grant Write permissions on the EntitySet in the InitializeService Method of the DataService

    Add this line to give you Write Permissions on the entitySet

    config.SetEntitySetAccessRule("EntitySetName",EntitySetRights.Write) 

    Phani Raj Astoria
    Monday, January 19, 2009 5:34 PM
    Moderator

All replies

  • Hi Ken,
     The 403 you are receiving is from the ADO.NET Data Services layer and not the HTTP Layer.
     You will need to grant Write permissions on the EntitySet in the InitializeService Method of the DataService

    Add this line to give you Write Permissions on the entitySet

    config.SetEntitySetAccessRule("EntitySetName",EntitySetRights.Write) 

    Phani Raj Astoria
    Monday, January 19, 2009 5:34 PM
    Moderator
  • To set the focus on a particular record of a DevExpress GridView we have to set the FocusedRowHandle property .We can get the RowHandle of the GridView by passing the primary key value.
    Below is the code for finding the RowHandle and setting the FocusedRowHandle property of the GridView.
     
    grdvEmployees.FocusedRowHandle = FindRowHandle (1100);
     
    In the above line of code ´1100' is the value of EmpID which is the primary key and we need to find that particular record having the EmpID as ´1100' and grdvEmployees is the name of the GridView.
     
    //This method returns the Row Handle by taking the primary key value as the parameter.
    private int FindRowHandle(int keyValue)
            {
                int retval = -1;
     
                if (keyValue == 0)
                {
                    return retval;
                }
     
                for (int count = 0; count < grdvEmployees.RowCount; count ++)
                {
                    if (Convert.ToInt32(grdvEmployees.GetRowCellValue(count, gcEmpID)) == keyValue)
                    {
                        retval = count;
                        break;
                    }
                }
     
                return retval;
            }
     
    In the above method ´gcEmpID' is the GridView's column name which holds the value for the primary key field.



    Cheers, Eliza
    Friday, February 26, 2010 1:23 PM