2

I am passed the request with post method. I want to validate the request(header/body) using filters. how I can configure the thing using Web api. below are my request :

x-ln-request:<?xml version="1.0" encoding="UTF-8" standalone="yes"?><ns2:requestToken xmlns:ns2="http://services.lexisnexis.com/xmlschema/request-token/1"><transactionID>2886f786-bd20-4220-932b-1bca1a9f7710</transactionID><sequence>1.2.2.2</sequence><contextualFeaturePermID>1000516</contextualFeaturePermID><featurePermID></featurePermID><billBackString descriptionPermId="">-None-</billBackString><isMandatoryBillbackEnforced>false</isMandatoryBillbackEnforced><cpmFeatureCode>47</cpmFeatureCode></ns2:requestToken>
x-ln-session:<?xml version="1.0" encoding="UTF-8"?><ns2:sessionToken xmlns:ns2="http://services.lexisnexis.com/xmlschema/session-token/1"><sessionID>c2e9d6f8-6505-4f59-a453-0f7014e58832</sessionID><issued>2014-03-24T02:59:31.484-04:00</issued><userPermIDUrn>urn:user:CA148686</userPermIDUrn><authorizationPermID>1000202</authorizationPermID><signature>v1-ffa9cbc5d0c27c7a36e1a2698fb11189</signature></ns2:sessionToken>
x-ln-i18n:
x-ln-retrieveoptions:
x-ln-application:

Body is :

<ns3:renderJob xmlns:ns2="http://services.lexisnexis.com/xmlschemas/linktemplate/1" xmlns:ns3="http://services.lexisnexis.com/shared/xmlschema/renderer/3" xmlns:ns4="http://services.lexisnexis.com/shared/xmlschema/coredataitem/2" xmlns:ns5="http://services.lexisnexis.com/shared/xmlschema/subdataitem/2" xmlns:ns6="http://services.lexisnexis.com/shared/xmlschema/clientmatter/1" xmlns:ns7="http://services.lexisnexis.com/shared/xmlschema/servicescommon/2>

How to call filters in webapi, can any one help me on this.

1 Answer 1

1

The validation can be performed broadly in two ways 1. Using filters 2. Global handlers You can check this below link for Filters http://www.dotnetcurry.com/showarticle.aspx?ID=927

  1. Using Global hanlders

Add a new class and use the below code

class SampleHandler : DelegatingHandler
{
    public SampleHandler ()
    {
    }

    protected override async Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
    {
        //TODO: Validation goes here

        HttpResponseMessage response = await base.SendAsync(request, cancellationToken);
        if (!response.IsSuccessStatusCode)
        {
            //_writer.WriteLine("{0}\t{1}\t{2}", request.RequestUri,
              //  (int)response.StatusCode, response.Headers.Date);
        }

        return response;
    }

}

Add this line in WebApiConfi file

config.MessageHandlers.Add(new SampleHandler());

Reference: http://www.asp.net/web-api/overview/formats-and-model-binding/model-validation-in-aspnet-web-api https://brettedotnet.wordpress.com/2013/05/01/asp-net-web-api-validation-a-one-more-better-approach/

I hope this will help you

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

Comments

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.