public string[] BuildServiceNames(string uriPrefix)
{
string hostname = ExtractHostname(uriPrefix, true);
IPAddress ipAddress = null;
if (String.Compare(hostname, "*", StringComparison.InvariantCultureIgnoreCase) == 0 ||
String.Compare(hostname, "+", StringComparison.InvariantCultureIgnoreCase) == 0 ||
IPAddress.TryParse(hostname, out ipAddress))
{
// for a wildcard, register the machine name. If the caller doesn't have DNS permission
// or the query fails for some reason, don't add an SPN.
try
{
string machineName = Dns.GetHostEntry(String.Empty).HostName;
return new string[] { "HTTP/" + machineName };
}
catch (System.Net.Sockets.SocketException)
{
return new string[0];
}
catch (System.Security.SecurityException)
{
return new string[0];
}
}
else if (!hostname.Contains("."))
{
// for a dotless name, try to resolve the FQDN. If the caller doesn't have DNS permission
// or the query fails for some reason, add only the dotless name.
try
{
string fqdn = Dns.GetHostEntry(hostname).HostName;
return new string[] { "HTTP/" + hostname, "HTTP/" + fqdn };
}
catch (System.Net.Sockets.SocketException)
{
return new string[] { "HTTP/" + hostname };
}
catch (System.Security.SecurityException)
{
return new string[] { "HTTP/" + hostname };
}
}
else
{
return new string[] { "HTTP/" + hostname };
}
}
}