locked
How to use ServiceOperation (OData/EF 4.0) RRS feed

  • Question

  • I have created a ServiceOperation which maps to a stored procedure in my database:

    public

    [W

    It is showing up correctly in the OData metadata:

    <FunctionImport Name="GetNearbyLocations" ReturnType="Collection(QPModel.NearbyLocations)" m:HttpMethod="GET">
    <Parameter Name="lat" Type="Edm.Single" Mode="In"/>
    <Parameter Name="lng" Type="Edm.Single" Mode="In"/>
    <Parameter Name="dist" Type="Edm.Int32" Mode="In"/>
    </FunctionImport>

     However whenever navigate to the URI http://localhost:1234/Services/OData.svc/GetNearbyLocations?lat=47.6062095&lng=-122.3320708&dist=5  I get the following error. 

    <error>
    <code/>
    <message xml:lang="en-US">Bad Request - Error in query syntax.</message>
    </error>

    Any help would be greatly appreciated!

    ebGet]
    public IQueryable<NearbyLocations> GetNearbyLocations(float lat, float lng, int dist)
    {
    var locations = (from l in this.CurrentDataSource.GetNearbyLocations(lat, lng, dist)
                    
    select l).AsQueryable();
    return locations;
    }
    static void InitializeService(DataServiceConfiguration config)
    {
    config.SetServiceOperationAccessRule(
    "GetNearbyLocations", ServiceOperationRights.All);
    config.SetEntitySetAccessRule(
    "*", EntitySetRights.AllRead);
    config.SetEntitySetPageSize(
    "*", 25);
    config.DataServiceBehavior.MaxProtocolVersion =
    DataServiceProtocolVersion.V2
    }
     
    static void InitializeService(DataServiceConfiguration config)
    {
    config.SetServiceOperationAccessRule(
    "GetNearbyLocations", ServiceOperationRights.All);
    config.SetEntitySetAccessRule(
    "*", EntitySetRights.AllRead);
    config.SetEntitySetPageSize(
    "*", 25);
    config.DataServiceBehavior.MaxProtocolVersion = DataServiceProtocolVersion.V2;
    }
    Thursday, June 10, 2010 3:11 AM

Answers

All replies

  • The data type of lat and long are "Single" - Please try to use

    lat=47.6062095f instead

     

    More on data type and querying syntax:

    http://msdn.microsoft.com/en-us/library/cc907912.aspx

    Note the section on "Edm.float":

    ‘[0-9]+.[0-9]+f’


    Regards,

    PQ


    Peter Q. http://blogs.msdn.com/peter_qian
    • Marked as answer by geekycyberdad Thursday, June 10, 2010 4:10 PM
    Thursday, June 10, 2010 4:55 AM
    Answerer
  • Thanks Peter.  This was exactly what I needed!
    Thursday, June 10, 2010 4:10 PM