none
Complex UriTemplate for WCF RRS feed

  • Question

  • I am totally new to WCF and web services.
     
    I need to create a REST based wcf service for which I have got the sample walkthrough from code project.
     
    I would like have the Uri Template like https://example.com/{v}/{resource}?filter={attribute}{op}{value}&sortBy={attributeName}&sortOrder={ascending|descending}&attributes={attribute list in csv}
     
    attribute:attribute to be searched 
    op:operator( format of eq,and,or,neq,like,contains ) value:attribute value to be searched
    attributeName:sortBy attribute name 
    sortOrder should be enum with ascending or descending. attributes:attributeslist in csv
     
    Is this possible?
     
    Could anyone help me in configuring UriTemplate and OperationContract for this?

    Thanks and Regards, Siva Kumar Balaguru

    Wednesday, December 18, 2013 11:20 AM

Answers

  • 
    
    [WebGet(UriTemplate = "/{v}/{resource}?filter={attribute_op_value}&sortBy={attributeName}&sortOrder={sortOrder}&attributes={attribute_list_in_csv}")]
    [OperationContract]
    IEnumerable<string> Search(string v, string resource, string attribute_op_value, string attributeName, string sortOrder, string attribute_list_in_csv);

    There is limitation for "{attribute}{op}{value}" pattern,because you should use name=value pairs. So in code you shoud parse it. There is no way to specify optional values like for sortOrder, it should be parsed in code.
    Wednesday, December 18, 2013 11:47 AM
  • Hi, Siva!

    You can supply them in coma separated format and parse in code, e.g. fileter = attr1,op1,value1. Other approach is to use fileterAttribute = {fattribute}&filterOp ={fop} and so on. If you definitely know number of elements. In case number of elements may varying use comma separation.

    Wednesday, December 18, 2013 12:50 PM

All replies

  • 
    
    [WebGet(UriTemplate = "/{v}/{resource}?filter={attribute_op_value}&sortBy={attributeName}&sortOrder={sortOrder}&attributes={attribute_list_in_csv}")]
    [OperationContract]
    IEnumerable<string> Search(string v, string resource, string attribute_op_value, string attributeName, string sortOrder, string attribute_list_in_csv);

    There is limitation for "{attribute}{op}{value}" pattern,because you should use name=value pairs. So in code you shoud parse it. There is no way to specify optional values like for sortOrder, it should be parsed in code.
    Wednesday, December 18, 2013 11:47 AM
  • Hi Sharov,

    If I use attribute_op_value for filter,how can I seperate the attribute,operator and value in the code?

    We'll get the filter data in the form of string with no seperator.

    And, how do I specify the attribute list in csv?

    Thanks


    Thanks and Regards, Siva Kumar Balaguru

    Wednesday, December 18, 2013 11:57 AM
  • Hi, Siva!

    You can supply them in coma separated format and parse in code, e.g. fileter = attr1,op1,value1. Other approach is to use fileterAttribute = {fattribute}&filterOp ={fop} and so on. If you definitely know number of elements. In case number of elements may varying use comma separation.

    Wednesday, December 18, 2013 12:50 PM