DataServiceException: Bad request - error in query syntax when calling service method...

Locked DataServiceException: Bad request - error in query syntax when calling service method...

  • Wednesday, February 10, 2010 4:47 AM
     
      Has Code
    I just started playing around with data services so I'm probably doing some newbie mistake or have misunderstood the url method invoke syntax. I created a simple custom data source and a data service based on it. Querying the IQueryable properties in the data source works fine, and I can filter etc (e.g. http://host/SomeService.svc/SomeEntities?$filter=Name%20eq%20'abc' ).

    Next I added a service method for results that always require a filter. Hitting the method without any parameters works fine (http://host/SomeService.svc/SomeEntityByName) and the method is invoked when I do so. But whenever I specify a parameter to the method (http://host/SomeService.svc/SomeEntityByName?name=abc) I get a System.Data.Services.DataServiceException: Bad Request - Error in query syntax. exception sent straight to HandleException and the method is never invoked.

    What is the correct method invoke url syntax for parameters?

    Service implementation (simplified for clarity):

    public class SomeService : DataService<MyCustomDataSource>
    
    {
    
      public static void InitializeService(IDataServiceConfiguration config) 
    
      {
    
        config.SetEntitySetAccessRule("*", EntitySetRights.AllRead);
    
        config.SetServiceOperationAccessRule("*", ServiceOperationRights.AllRead);
    
      }
    
    
    
      protected override void HandleException(HandleExceptionArgs args)
    
      {
    
      ...
    
      }
    
    
    
      [WebGet]
    
      public IQueryable<SomeEntity> SomeEntityByName(string name)
    
      {
    
        return base.CurrentDataSource.SomeEntities.Where(u => u.Name == name).AsQueryable();
    
      }
    
    }
    
    
    
    public class MyCustomDataSource
    
    {
    
      public IQueryable<SomeEntity>SomeEntities
    
      {
    
        get { ... }
    
      }
    
    }
    
    

    Exception details:

    System.Data.Services.DataServiceException: Bad Request - Error in query syntax.
    
       at System.Data.Services.RequestUriProcessor.ReadOperationParameters(DataServiceHostWrapper host, ServiceOperationWrapper operation)
    
       at System.Data.Services.RequestUriProcessor.CreateFirstSegment(IDataService service, String identifier, Boolean checkRights, String queryPortion, Boolean isLastSegment, Boolean& crossReferencingUrl)
    
       at System.Data.Services.RequestUriProcessor.CreateSegments(String[] segments, IDataService service)
    
       at System.Data.Services.RequestUriProcessor.ProcessRequestUri(Uri absoluteRequestUri, IDataService service)
    
       at System.Data.Services.DataService`1.ProcessIncomingRequestUri()
    
       at System.Data.Services.DataService`1.HandleRequest()
    
    

    Environment: .net 3.5 SP1, VS2008, KB976127v6, Win7x64




    Kristofer - Huagati Systems Co., Ltd.
    Cool tools for Linq-to-SQL and Entity Framework:
    huagati.com/dbmltools (add-in with new features for Visual Studio 2008's L2S and EF designers)
    huagati.com/L2SProfiler (Query profiler for Linq-to-SQL and LLBLGen Pro)

All Replies

  • Wednesday, February 10, 2010 10:37 AM
     
     
    Ah, never mind, I was just being stupid...   ...I had left out the leading ' and trailing ' around the string parameter's literal...

    I wish I could have blamed it on 'Monday morning syndrome', but today is Wednesday so I have to come up with some better excuse... :)
    Kristofer - Huagati Systems Co., Ltd.
    Cool tools for Linq-to-SQL and Entity Framework:
    huagati.com/dbmltools (add-in with new features for Visual Studio 2008's L2S and EF designers)
    huagati.com/L2SProfiler (Query profiler for Linq-to-SQL and LLBLGen Pro)