1

I've been using service stack for a while and came upon a scenario where the POST method uses the default instance of the IReturn object (with all the properties defaulting to their datatype values). The values supplied as part of the Route (/product/1234345/) are the only ones populated. I've laid out an example below:

[Route("/search/{searchMethod}/books")]
public class SearchRequest : IReturn<SearchResponse>
{
    public SearchProvider searchProvider { get; set; }

    public string searchTerm { get; set; }

    public string categoryID { get; set; }

    public long maxResults { get; set; }

    //Only this property gets populated if method is post
    public string searchMethod { get; set; }
}

public SearchResponse Any(SearchRequest searchRequest)
{
    //This works only for non-post requests
    return Put(searchRequest);
}

public SearchResponse Get(SearchRequest searchRequest)
{
    //This works
    return Put(searchRequest);
}

public SearchResponse Post(SearchRequest searchRequest)
{
    //This does not
    return Put(searchRequest);
}

public SearchResponse Put(SearchRequest searchRequest)
{
    //Code for put method goes here            
}

I'm then using a client to call these methods

SearchServiceClient searchClient = new SearchServiceClient(SearchServiceAPIUrl);

SearchResponse searchResponse = searchClient.Search(SearchProvider.SampleSearchProvider, searchterm, categoryID, 100,"conservative");

Any help is really appreciated

Thanks

jammerman
  • 49
  • 4

2 Answers2

1

I've always just populated my request object in the constructor and sent it to the service

    searchClient.Post(new SearchRequest(SearchProvider.SampleSearchProvider, 
                                       searchterm, categoryID, 100,"conservative")):
CSharper
  • 5,420
  • 6
  • 28
  • 54
1

I finally found the solution after tinkering with the DTO. It seems for post requests all DTO properties needed to have a [DataMember] attribute for serialization/deserialization and make sure that the class also has a [DataContract] attribute.

jammerman
  • 49
  • 4
  • That doesn't sound right, what serializer is `SearchServiceClient` using? Does it inherit an existing ServiceStack ServiceClient? If it's JSON the `[DataContract]` and `[DataMember]` attrs make serialization opt-in where [every property needs to be decorated or none do](http://stackoverflow.com/a/14859968/85785). – mythz Apr 25 '15 at 01:24