1
Vote

UriTemplateMatch unavailable?

description

I'm trying to get the UriTemplateMatch from the following

WebOperationContext.Current.IncomingRequest.UriTemplateMatch

within my service contract but it's always null. I'm trying to create resource links in my return message.

comments

jberd126 wrote Oct 6, 2011 at 6:58 PM

Can the 'added' portion below be added?

namespace Microsoft.ApplicationServer.Http.Dispatcher
{
public class UriTemplateHandler : HttpOperationHandler
{
    protected override sealed object[] OnHandle(object[] input)
    {
        ...

        Uri uri = requestMessage.RequestUri;
        int numberOfParameters = this.OutputParameters.Count;
        object[] output = new object[numberOfParameters];
        if (uri != null)
        {
            UriTemplateMatch match = this.UriTemplate.Match(this.BaseAddress, uri);

            if (match == null)
            {
                throw Fx.Exception.AsError(
                    new InvalidOperationException(
                        Http.SR.UriTemplateDoesNotMatchUri(
                            uri.ToString(),
                            this.UriTemplate.ToString())));
            }

            // BEGIN added 
            var webOperationContext = System.ServiceModel.Web.WebOperationContext.Current;
            if(webOperationContext != null)
            {
                webOperationContext.IncomingRequest.UriTemplateMatch = match;
            }
            // END added 

            for (int i = 0; i < numberOfParameters; i++)
            {
                output[i] = match.BoundVariables[i];
            }
        }

        return output;
    }
}
}