This was asked on the new Stack Overflow programming questions site recently (which you should really check out and start using if you don’t already!). Getting the SSP name is something that I’ve needed to do to build the SSP URL for impersonating access to the Project Server PSI. I used to think that the URL had to live in a config file. Then after some digging into Project Server’s behaviour with the help of Reflector, I discovered Microsoft use the SharedResourceProvider class in the Microsoft.Office.Server.Administration namespace. Who knows why, but this class is marked internal so reflection is required to access it, and therefore accessing it is not supported. We should be on relatively safe ground if MS products such as Project Server use it however…
The following code retrieves the name of the SSP for the current site collection.
SPSite site = SPContext.Current.Site;
ServerContext serverContext = ServerContext.GetContext(site);
PropertyInfo srpProp = serverContext.GetType().GetProperty(
BindingFlags.NonPublic | BindingFlags.Instance);
object sharedResourceProvider = srpProp.GetValue(serverContext, null);
PropertyInfo srpName = sharedResourceProvider.GetType().GetProperty(
BindingFlags.Public | BindingFlags.Instance);
string sspName = (string)srpName.GetValue(sharedResourceProvider, null);
From there the URL to the PSI web services within the SSP directly becomes the following (and the port number is always the following on every server):
This does seem overly complex so if someone out there has a better solution please add it as a comment to this blog or update the answer on Stack Overflow.