DataServiceRequestException FOR CRUD OPERATIONS RRS feed

  • General discussion

  • I have simple ADO.ENTITY MODEL FOR Customers from Northwind database which is exposed as a WCF Data Service.

    I have set the EntitySetAccessRules to "All" but still i am not able to insert records into my database.

    The call to entity.SaveChanges() or dataServiceContext.SaveChanges() throws an exception.

    I get

    I am using windows 7, VS 2010, .net framework 4 and sql server 2008 r2 express edition for development

    Here is my code

    using System;
    using System.Collections.Generic;
    using System.Data.Services;
    using System.Data.Services.Common;
    using System.Linq;
    using System.ServiceModel.Web;
    using System.Web;

    [System.ServiceModel.ServiceBehavior(IncludeExceptionDetailInFaults = true)]
    public class WcfDataService : DataService<NorthwindEntities >

      // This method is called only once to initialize service-wide policies.
     public static void InitializeService(DataServiceConfiguration config)

      // TODO: set rules to indicate which entity sets and service operations are visible, updatable, etc.
      // Examples:
        config.SetEntitySetAccessRule("*", EntitySetRights.All);
        config.SetServiceOperationAccessRule("*", ServiceOperationRights.All);
        config.DataServiceBehavior.MaxProtocolVersion = DataServiceProtocolVersion.V2;



     and my client code is

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using ConsoleApp.NorthwindService;
    using System.Data.Services.Client;

    namespace ConsoleApp

    class Program

      static void Main(string [] args)

       Uri serviceUri = new Uri("http://localhost:57212/WcfDataService.svc/" );
      DataServiceContext dataServiceContext = new DataServiceContext(serviceUri);

             NorthwindEntities entites = new NorthwindEntities(serviceUri);

      Customer cust = new Customer();

      cust.CustomerID ="ABC" ;
      cust.CompanyName ="DEF" ;
      cust.City ="GHI" ;
      cust.ContactTitle ="JKL" ;
      cust.ContactName ="MNO" ;
      cust.Address ="PQR" ;
      cust.Region ="STU" ; 


       dataServiceContext.AddObject("Customers", cust);

       Console.WriteLine("Successfully inserted the record.");

      catch (DataServiceRequestException ex)

       Console .WriteLine(ex.Message);

      Console .ReadLine();



    How do i resolve this problem ? Can somebody help > ???





    Tuesday, April 12, 2011 9:42 AM

All replies

  • Hi,

    Can you please post some details about the exception you're getting? Ideally the full dump (message, stacktrace, ...).

    Also a Fiddler trace of the communication between client and server would help.

    Also, please set config.UseVerboseErrors = true in your service initialization (just for debugging).


    Vitek Karas [MSFT]
    Tuesday, April 12, 2011 9:52 AM