none
Passing a Querystring to a service with basicHttpBinding RRS feed

  • Question

  • Hi,

    I'm faced with the probably unusual problem to pass a querystring to a service that uses the basicHttpBinding (*NOT* the webHttpBinding). The querystring parameter is not supposed to be passed by the service consumer directly. But I want to use the UrlRewrite Module of IIS 7 to map part of the Url to the querystring.

    Example:

    The service is physically hosted under the address http://myserver/myservice.svc

    But I want the consumer to address the service like http://myserver/test-env/myservice.svc. After rewriting the Url the service should be called like http://myserver/myservice.svc?stage=test-env.

    I implemented the Url rewriting with the UrlRewrite Module 2.0 of IIS 7 and it works perfectly.

    BUT: How can I access the querystring inside the service implementation? I found no answer to that question on MSDN or the internet.

    I found the property OperationContext.Channel.LocalAddress which contains the address http://myserver/myservice.svc but the querystring is truncated.

    I could activate the aspNetCompatibility mode and use HttpContext.Current.Request to access the querystring but I don't like that for performance reasons.

    So: How can I access the querystring part of the service Url from inside the service?

    Thanks,

    Robert

    Wednesday, September 14, 2011 12:38 PM

Answers

  • Hi Robert,

    There is a property called HttpRequestMessageProperty that can return the query string.  Try this:

    string query_string;
    
    
    OperationContext context = OperationContext.Current;
    
    
    MessageProperties msgproperties = context.IncomingMessageProperties;
    
    HttpRequestMessageProperty requestProperty = msgproperties[HttpRequestMessageProperty.Name] as HttpRequestMessageProperty;
    
    query_string = requestProperty.QueryString; 
    
    

     


    Tom Overton
    • Marked as answer by Robesand Wednesday, September 14, 2011 2:18 PM
    Wednesday, September 14, 2011 1:29 PM

All replies

  • Hi Robert,

    There is a property called HttpRequestMessageProperty that can return the query string.  Try this:

    string query_string;
    
    
    OperationContext context = OperationContext.Current;
    
    
    MessageProperties msgproperties = context.IncomingMessageProperties;
    
    HttpRequestMessageProperty requestProperty = msgproperties[HttpRequestMessageProperty.Name] as HttpRequestMessageProperty;
    
    query_string = requestProperty.QueryString; 
    
    

     


    Tom Overton
    • Marked as answer by Robesand Wednesday, September 14, 2011 2:18 PM
    Wednesday, September 14, 2011 1:29 PM
  • Hi Tom,

    thanks, you made my day!

    Robert

     

    Wednesday, September 14, 2011 2:18 PM