This project is read-only.

How to have input parameters

Topics: Web Api
Nov 17, 2011 at 2:26 PM

Sorry for the noob question, but this is my first time using this project and am having difficulties. I am trying to add a web method like so:

[WebGet(UriTemplate = "ReadActiveJobsForToday")]
        public WebResult<List<Job>> ReadActiveJobsForToday(int userId)
            var result = new WebResult<List<Job>>();
                using (new SessionScope())
                    var views = new List<Job>();

                    //get vehicle associated to user.
                    var vehicle = VehicleData.FindByDriver(userId);
                    if (vehicle == null)
                        result.Success = false;
                        result.ErrorMessage = "There is no vehicle associated to the user with id " + userId;
                        return result;

                    //get vehicle's jobs.
                    var jobs = JobData.FindAllActive(vehicle.IPAddressNumber);

                    //convert to view.
                    views = ConvertToView(jobs);

                    result.Result = views;
                    result.Success = true;
            catch (Exception exc)
                result.Success = false;
                result.ErrorMessage = exc.ToString();
            return result;

When I go to the test page - http://localhost:9000/api/jobs/test/home - I get this error:

The service operation 'ReadActiveJobsForToday' will never receive a value for the input parameter 'userId' of type 'Int32'. Ensure that a request HttpOperationHandler has an output parameter with a type assignable to 'Int32' or that the output parameter has the name 'userId' and provides a string value that can be parsed as a 'Int32'.

So how exactly am I supposed to have web methods that have required parameters? I did the quick start tutorial but it only shows an example where there are no parameters (besides the ODATA querying.)

Nov 17, 2011 at 2:47 PM


[WebGet(UriTemplate = "ReadActiveJobsForToday/{userId}")]

and specify some value for user id during the request.
Nov 17, 2011 at 2:59 PM

Works great, thanks!

Jan 24, 2012 at 2:09 PM

A good one.thanks