Jean-Louis Kroon
Jean-Louis Kroon

Reputation: 71

Servicestack Query String

I Am trying to link values from a set query string to attributes in a service stack object.

The following code snippet illustrates what I am trying to achieve. (I want to map FN to SenderNumber, TN to ContactNumber etc.)

[Route("/smscallback?FN={SenderNumber}&TN={ContactNumber}&MS={Response}&TS={TS}")]
public class SmsCallback : IReturn<SmsCallbackResponse>
{
    public string SenderNumber
    {
        get;
        set;
    }
    public string ContactNumber
    {
        get;
        set;
    }
    public string Response
    {
        get;
        set;
    }
    public string TS
    {
        get;
        set;
    }
}

Does anyone know how to do this? I have looked at the routing example servicestack provides but I am having trouble to apply that to my situation.

Thank you.

Upvotes: 4

Views: 2044

Answers (1)

mythz
mythz

Reputation: 143284

Please re-read the Routing wiki page:

Note: The QueryString, FormData and HTTP Request Body isn't apart of the Route (i.e. only the /path/info is) but they can all be used in addition to every web service call to further populate the Request DTO.

You can't put any queryString in the route. If you want to change what the fields get mapped to you need to decorate your DTO with DataContract/DataMember attributes, e.g:

[DataContract]
public class SmsCallback : IReturn<SmsCallbackResponse>
{
    [DataMember(Name="fn")]
    public string SenderNumber { get; set; }

    [DataMember(Name="tn")]
    public string ContactNumber { get; set; }

    [DataMember(Name="ms")]
    public string Response { get; set; }

    [DataMember]
    public string TS { get; set; }
}

Upvotes: 6

Related Questions