Here's code that returns the msd path. I don't know of a way to get the original url. (Remember, one or more web adaptors may be used for a service, each with a different hostname). The path to the msd could be parsed and used to construct the portions of the url containing the folder and mapservice name.
For testing I find it helpful to also know the processID, which makes it easier to attach a debugger.
private byte[] RootResHandler(NameValueCollection boundVariables, string outputFormat,
string requestProperties, out string responseProperties)
{
responseProperties = null;
JsonObject result = new JsonObject();
var id = System.Diagnostics.Process.GetCurrentProcess().Id;
result.AddString("Machine", Environment.MachineName);
result.AddString("ProcessID", id.ToString());
var svrInit = m_serverObjectHelper.ServerObject as IMapServerInit2;
if (svrInit != null)
{
if (!string.IsNullOrEmpty(svrInit.FilePath))
result.AddString("filepath", svrInit.FilePath);
else
result.AddString("filepath", "null filepath");
}
else
result.AddString("filepath", "no svrInit");
return Encoding.UTF8.GetBytes(result.ToJson());
}