MSantos
MSantos

Reputation: 53

c# Uri Templates

I'm new to REST service development and I am currently writing a WCF Rest Service which must support an existing calling format.

I know that by adding

[WebInvoke(Method = "GET", UriTemplate = "{id}/testid.xml")]
string testid(string id);

to my webmethod the request will be made using:

http://[hostname]/255/testid.xml

What I want is to be able do make the request using http://255/[hostname]/testid.xml

Please note that the service is hosted in a Windows Service Application.

Thanks for your help!

Upvotes: 1

Views: 737

Answers (3)

tom redfern
tom redfern

Reputation: 31780

You can't. The structure of a given URI is as follows:

eg http://host/path?q=x

This can be broken down into:

  • http:// - the Scheme
  • host/ - the Authority
  • path - the Path
  • ?q=x - the Querystring

URI templating works on the Path and Querystring components of the URI only. The Scheme and the Authority cannot be accessed in this way.

Upvotes: 1

Shivanand Baste
Shivanand Baste

Reputation: 84

It is not possible. you can't add parameter or can't pass parameter in uri before domain name and service name. You can add parameter after domain and service name in Uri.

Upvotes: 0

Ruben Aguilar
Ruben Aguilar

Reputation: 1235

To use special characters inside parameters on the URL you must configure the HttpListenerRequestUriBuilder. This builder unescape or not the encoding based on a setting. You can add this code to your app.config file:

<configuration>
  <system.net>
    <settings>
      <httpListener unescapeRequestUrl="false"/>
    </settings>
  </system.net>
</configuration>

Upvotes: 0

Related Questions