locked
Validate the UriTemplate in my REST Service RRS feed

  • Question

  • User-844296933 posted

    I have this REST service:

       [WebInvoke(Method = "GET", ResponseFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.Wrapped, UriTemplate = "LoadPostings/?OriginCode={OriginCode}&DestinationCode={DestinationCode}&EquipmentTypeId={EquipmentTypeId}&IsTruckLoad={IsTruckLoad}&SessionId={SessionTokenId}")]
        SupplierLoadSearchResults GetLoadPostings(string OriginCode, string DestinationCode, int EquipmentTypeId, string IsTruckLoad, string SessionTokenId);
    

    This is the UriTemplate:

    UriTemplate = "LoadPostings/?OriginCode={OriginCode}&DestinationCode={DestinationCode}&EquipmentTypeId={EquipmentTypeId}&IsTruckLoad={IsTruckLoad}&SessionId={SessionTokenId}"

    I noticed that when the Incoming Request changes the name of the resource for example:

    Change EquipmentTypeId to something like EquipmentId

    .NET does not give me an error on that, in face what does happen is the I get a 0 value (because in this case the EquipmentTypeId is an int) And that 0 is being passed to my database layer and breaks there.

    Is there a way to validate the UriTemplate in .net ?

    I wrote down this code to compare the keys between teh UriTempalte and what the user sends me, but I wonder if there is a better way to validate the UriTemplate?


    NameValueCollection incomingQueryParams = WebOperationContext.Current.IncomingRequest.UriTemplateMatch.QueryParameters; System.Collections.ObjectModel.ReadOnlyCollection<String> templateQueryParams = WebOperationContext.Current.GetUriTemplate("GetLoadPostings").QueryValueVariableNames;

    Friday, May 3, 2013 11:03 AM

Answers

  • User-1000095884 posted

    Hi,

    Take a look at the reply in this duplicated thread by determine matches between the request uri with a UriTemplate, if it not anwser yout issue, please give a feedback here.

    Best Regards.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, May 7, 2013 4:10 AM

All replies

  • User220959680 posted

    rperetz

    UriTemplate = "LoadPostings/?OriginCode={OriginCode}&DestinationCode={DestinationCode}&EquipmentTypeId={EquipmentTypeId}&IsTruckLoad={IsTruckLoad}&SessionId={SessionTokenId}"

    [Description("This method does ......etc")]
    LoadPostings/{OriginCode}/{DestinationCode}/{EquipmentTypeId}/{IsTruckLoad}/{SessionTokenId}

    Client can read API documentation by navigating to http://<ServiceURI\Help> where the above description is self explanatory.

    Make sure to add this configuriaton in Web.config 

     <serviceMetadata httpGetEnabled="true"/>


    Friday, May 3, 2013 11:40 AM
  • User-1000095884 posted

    Hi,

    Take a look at the reply in this duplicated thread by determine matches between the request uri with a UriTemplate, if it not anwser yout issue, please give a feedback here.

    Best Regards.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, May 7, 2013 4:10 AM