1

Am am building ASP.NET WEB API for one of my projects where I have generic request message which contains some generic properties. I want to build DelegatingHandler inside which I will be able to get strongly typed model from request (no matter is it JSON request or XML) as IRequestMessage and validate some of its properties. is it possible and how can I achieve that?

public class MessageValidationHandler : DelegatingHandler
{
    protected override Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
    {
         //what to do to get strongly typed model from request?
    }
}
1
  • I would like to know the way I can access that information if I know that I would not open this question
    – Rati_Ge
    Commented Jun 12, 2013 at 21:39

1 Answer 1

-1

This is what you can do:

    protected override async Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, System.Threading.CancellationToken cancellationToken)
    {
        var response = await base.SendAsync(request, cancellationToken);

        MyType type;

        if (response.TryGetContentValue(out type))
        {
            // Yay! let's do something with this!
        };

        return response;
    }
2
  • don't you think this will make my handler to pass data to API controller? I would like to find data as ealier as possible so I would no call base.SendAsync(request, cancellationToken); is there is error with predefined validation mechanism.
    – Rati_Ge
    Commented Jun 20, 2013 at 20:55
  • Oh, I'm sorry, I misunderstood. I thought you meant getting to the model returned from the controller, not the model that goes in. Commented Jun 21, 2013 at 7:07

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.