Getting the base Uri for location header

Topics: Web Api
Sep 22, 2011 at 10:38 AM

How would I build the location Uri for create request in my service? Where do I get the base Uri to use.

For example:

public HttpResponseMessage Create(string name)
{
  // build location string
 var baseUri = ????
 var resourceUri = new Uri(baseUri, "resource/name");

  return new CreatedMessage(resourceUri); // returns httpstatuscode Created and given uri as the location for the created resource
}

I'm running my service inside Azure.

Coordinator
Sep 22, 2011 at 6:24 PM

You should grab the request URI and use that as your baseUri. Simply change your operation parameter to be HttpRequestMessage<string> and then grab the RequestUri property.

Daniel Roth

From: pekkah [email removed]
Sent: Thursday, September 22, 2011 3:39 AM
To: Daniel Roth
Subject: Getting the base Uri for location header [wcf:273447]

From: pekkah

How would I build the location Uri for create request in my service? Where do I get the base Uri to use.

For example:

public HttpResponseMessage Create(string name)
{
  // build location string
 var baseUri = ????
 var resourceUri = new Uri(baseUri, "resource/name");
 
  return new CreatedMessage(resourceUri); // returns httpstatuscode Created and given uri as the location for the created resource
}

I'm running my service inside Azure.