1

I'm trying to build a Web API for a complex type of searching. I want to support paging in the results. The "state" of the search is complex, so not really suitable for persisting in the query string. But I'd like for the paging options to be included within the query string.

I've implemented two methods, as below, and the web api code seems to understand what I'm trying to do, but the query string parameters never get assigned. Any hints or advice on this would be appreciated:

public Task<HttpResponseMessage<SearchResults>> Post(SearchRequest request) //Method 1
{
    return Post(request, null, null);
}

public async Task<HttpResponseMessage<SearchResults>> Post(SearchRequest request, string page, string pageSize) //Method 2
{
    //All of the complex code, including...
    if (PageNo < TotalPages)
    {
        searchResults.AddLink(new Link { Uri = Url.Route("DefaultApi", new {
             controller = "AdvancedSearch",
             page = (PageNo + 1).ToString(),
             pageSize = PageSize.ToString() }),
             Relation = "nextPost" });
    }
    //Final wrap up, etc
}

On POSTing a SearchRequest to /api/AdvancedSearch, Method 1 is called, which in turn calls Method 2, which does the search, and packages up the results. As you can hopefully see, included in this result (if more pages of results are available) is a URL to post to for the next page. The generated URL base on this is /api/AdvancedSearch?page=2&pageSize=20, exactly as I'd hoped.

In my calling code, I then perform a POST to this second URL. Only Method 2 is invoked (as expected). But, both page and pageSize are null.

What am I doing wrong? Or what else do you need to see in order to answer this question?

5
  • HttpResponseMessage<T> is being dropped so you might need to redesign yours. Commented May 9, 2012 at 9:55
  • @Aliostad - do you have a link to that change? What's the replacement to be? Commented May 9, 2012 at 10:01
  • Download the latest from aspnetwebstack.codeplex.com and you will see that latest System.Net.Http.dll does not have it anymore. Commented May 9, 2012 at 10:14
  • I'm having this same problem , am wondering whether its due to using the beta release and not the nightly build? Commented May 22, 2012 at 16:25
  • @Tim - I've not managed to move forward from the beta release myself. This was for a prototype and, for the time being, I'm manually populating the parameters inside the function - with the intention to revisit this issue later if the prototype is successful. Commented May 23, 2012 at 7:36

1 Answer 1

0

Below is not needed

You need to decorate your parameters using [FromUri]:

public async Task<HttpResponseMessage<SearchResults>> Post(SearchRequest request, 
   [FromUri]string page, 
   [FromUri]string pageSize)


As I said in the comments, HttpResponseMessage<T> is being dropped since the Content property of HttpResponseMessage will perform all needed operations.


I checked and I passed querystring params in a post, no problem.

Sign up to request clarification or add additional context in comments.

2 Comments

@Damien_The_Unbeliever let me have a look.
@Damien_The_Unbeliever I checked and I passed querystring params in a post, no problem.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.