locked
Silverlight 4.0 and WCF Data services access issue RRS feed

  • Question

  • Hi,

    I have:

        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;
          config.UseVerboseErrors = true;
    
        }
    when I call the service from the client using

    BeginSaveChanges

    essvc.BeginSaveChanges(SaveChangesOptions.Batch, OnChangesSaved, essvc);

    I receive forbidden error:

    --batchresponse_a7bc1f95-8f8d-4e3b-9e24-108743499c3a
    Content-Type: multipart/mixed; boundary=changesetresponse_04a92dd2-1fe4-4da5-8d2e-e020fe354f8f
    
    --changesetresponse_04a92dd2-1fe4-4da5-8d2e-e020fe354f8f
    Content-Type: application/http
    Content-Transfer-Encoding: binary
    
    HTTP/1.1 403 Forbidden
    Content-ID: 1
    DataServiceVersion: 1.0;
    Content-Type: application/xml
    
    <?xml version="1.0" encoding="utf-8" standalone="yes"?>
    <error xmlns="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata">
     <code></code>
     <message xml:lang="en-US">Forbidden</message>
    </error>
    --changesetresponse_04a92dd2-1fe4-4da5-8d2e-e020fe354f8f--
    --batchresponse_a7bc1f95-8f8d-4e3b-9e24-108743499c3a--
    

    Any help is appreciated.

    cheers

    Valko

    Friday, June 11, 2010 2:12 PM

Answers

  • Try setting a breakpoint in your InitializeService method to verify it is really called.

    Pawel

    • Marked as answer by Valko Friday, June 11, 2010 5:12 PM
    Friday, June 11, 2010 4:08 PM
  • hi,

    just find answer to my own question, override the HandleException in the wcf service

      protected override void HandleException(HandleExceptionArgs args)
      {
       // need this to create a breakpoint and debug errors
       base.HandleException(args);
      }
    

    and voila, F9 breakpoint and nice inner exception showing me trying to send some NULL data to the database.

    cheers

    Valko

    • Marked as answer by Valko Friday, June 11, 2010 5:12 PM
    Friday, June 11, 2010 5:12 PM

All replies

  • Try setting a breakpoint in your InitializeService method to verify it is really called.

    Pawel

    • Marked as answer by Valko Friday, June 11, 2010 5:12 PM
    Friday, June 11, 2010 4:08 PM
  • thank you Pawel,

    that was my first thought, but

    if you can tell me how exactly I can debug both Silverlight 4 and WCF data service running both in same web project that will help definitely,

    I have other post for that: http://social.msdn.microsoft.com/Forums/en-US/adodotnetdataservices/thread/9363ca9b-2693-41c0-9b8a-20aa876fba11

    when I start the Silverlight the wcf service is grayed out and I cant attach the debugger.

    cheers

    Valko

    Friday, June 11, 2010 4:23 PM
  • hi,

    just find answer to my own question, override the HandleException in the wcf service

      protected override void HandleException(HandleExceptionArgs args)
      {
       // need this to create a breakpoint and debug errors
       base.HandleException(args);
      }
    

    and voila, F9 breakpoint and nice inner exception showing me trying to send some NULL data to the database.

    cheers

    Valko

    • Marked as answer by Valko Friday, June 11, 2010 5:12 PM
    Friday, June 11, 2010 5:12 PM
  • I just created a sample silverlight app in VS 2010. When I debug the application I can set breakpoints to both the ASP.NET side and the Silverlight side (when I hit F5, it attached to both the server and the IE). The same should work for you. Please set the debugger to catch all exceptions (Ctrl + Alt + E and check the checkbox for "Thrown" for "Common Language Runtime Exceptions") and try to run your project. It should catch the exception on the server as well. If it still doesn't work, turn off "Just my code debugging" (it's in the VS settings under Debugger), make sure you stop on all exceptions again, and try again.

    Thanks,


    Vitek Karas [MSFT]
    Friday, June 11, 2010 5:12 PM
    Moderator