HttpOperationHandler not populating complex params on DELETE

Topics: Web Api
Feb 6, 2012 at 10:52 AM

I'm using WCF Web API Preview 6 and I've come across a strange issue, not sure exactly where I'm going wrong.

My API service uses a simple key authentication which is set in the headers of each request.  I've built a HttpOperationHandler that inspects the headers, authenticates the key and populates an AuthenticationTicket with the user's account ID so I can use it in the service method body:

    public class AuthenticationHandler : HttpOperationHandler<HttpRequestMessage, AuthenticationTicket>
        private readonly IAuthenticator authenticator;

        public AuthenticationHandler(IAuthenticator authenticator)
            : base("response")
            this.authenticator = authenticator;

        protected override AuthenticationTicket OnHandle(HttpRequestMessage input)
            var result = authenticator.Validate(input);
            if (result.Success && result.AccountId.HasValue)
                var ticket = new AuthenticationTicket(result.AccountId.Value);
                return ticket;
            throw new HttpResponseException(HttpStatusCode.Unauthorized);

GET requests work fine with this, so for instance in one of my service methods:

        [WebInvoke(UriTemplate = "surveys/{surveyId}", Method = "GET")]
        HttpResponseMessage<Survey> LoadSurvey(AuthenticationTicket ticket, string surveyId);

Both the ticket and survey ID are populated with values.

However, with a DELETE method only the surveyId is populated, the AuthenticationTicket is null.

        [WebInvoke(UriTemplate = "surveys/{surveyId}/delete", Method = "DELETE")]
        HttpResponseMessage DeleteSurvey(AuthenticationTicket ticket, string surveyId);

I've stepped through the code and the AuthenticationHandler is firing for this request, and returning a valid result but the parameter of the method isn't being populated.

Is this a bug or am I doing something wrong?

Thanks in advance.

Feb 6, 2012 at 11:07 AM

Update: The same happens for PUT and POST requests too.  This only seems to work with GET requests.

Feb 6, 2012 at 4:50 PM

You need to change the parameter name to be "ticket". Currently its set to "response".


        public AuthenticationHandler(IAuthenticator authenticator)            : base("ticket")

Feb 7, 2012 at 11:19 AM

This issue has slowly been driving me insane.  Your fix works perfectly digitalpacman, thank you very much!