WCF Service with Stored Procedures

2 posts, 0 answers
  1. Patrick
    Patrick avatar
    14 posts
    Member since:
    May 2011

    Posted 25 Sep 2013 Link to this post

    Hi there,

    we have created a WCF webservice using OpenAccess from Telerik and it works all fine with entities and views.
    We are now trying to use some stored procedures but we are not able to access them like we do with the tables and views.

    What we've done sofar was creating a partial class to extend the EntitiesModelService with a method to call the stored procedure.
    We've already created a Domain Method for the stored procedure in the model.

    public partial class EntitiesModelService
        {
            [WebGet]
            public IEnumerable<Store> FncGetNearbyPlaces(float? lat, float? lng, float? distance)
            {
                return (new EntitiesModel()).FncGetNearbyPlaces(lat, lng, distance);
            }
        }

    and added this line in the EntitiesModelService

    public static void InitializeService(DataServiceConfiguration config)
       {
                ...
       config.SetServiceOperationAccessRule("FncGetNearbyPlaces", ServiceOperationRights.All);
      
       }


    we have followed the indications on this post: http://www.telerik.com/community/forums/orm/getting-started/using-stored-procedures-in-entity-model-with-a-service.aspx

    Thanks in advance for your help!!!

    Antonio.
  2. Viktor Zhivkov
    Admin
    Viktor Zhivkov avatar
    291 posts

    Posted 26 Sep 2013 Link to this post

    Hello Patrick,

    I believe that you have used the right code and configuration for your custom Data Service method.
    How did you try to call your method?
    Calling a method with float parameters can be a bit tricky but can be done using the following request pattern:
    // provide all arguments for all parameters
    http://[host]:[port]/EntitiesModelService.svc/FncGetNearbyPlaces?lat=1.0f&lng=75.0f&distance=10f
     
    // provide arguments for some parameters
    http://[host]:[port]/EntitiesModelService.svc/FncGetNearbyPlaces?lat=40.0f&distance=100.5f

    The most important thing there is to use the right representation for the parameter type - in your case you have to append "f" suffix to the float value.

    If  you had trouble getting a Service Reference proxy in a .Net client application with code to call the custom operation you can read this article. There you can find explanation why no code is generated for service operations and what to do in order to call one.

    If you need any further assistance do not hesitate to contact us with your questions.

    Regards,
    Viktor Zhivkov
    Telerik
    OpenAccess ORM Q3 2013 Beta is available for immediate download in your account. Get it now and play with the latest bits. See what's new >>
  3. DevCraft banner
Back to Top