As you may have noticed in my previous post I called the SSP in my code using hard-coded text..
string sspname = "SharedServices1";
ServerContext current = ServerContext.GetContext(sspname);
Apart from the fact that I'm a bit ashamed by doing this there was a reason why it was still hard-coded and that was because I couldn't find an easy way to determine if a SPWebApplication was a SSP. All the examples from Microsoft on TechNet show the following snippets when try to open a SSP in code :
Not very helpful eh ? :) Now with some Googling I found the following blog : Chris Hernandez's Blog with the following post Creating Shared Service Provider (SSP) via command-line options and in the comments section there is the answer to retrieve the SSP Web Applications while looping through the Web Applications. While you are looping there is a certain property in the propertybag that identifies what kind of webapplication it is and apparently for a SSP that key is :
spWebApp.Properties.ContainsKey("Microsoft.Office.Server.SharedResourceProvider")
Now we get all the WebApplications that use the Microsoft.Office.Server.SharedResourceProvider! Next step is to filter the MySites SSP from the Admin SSP ;) And that is pretty easy since we know that the mysites are using their own sitetemplates (MSITEHOST) and the admin page is created using the "OSRV" sitetemplate. By having narrowed down all possibilities we can get the ServerContext of our admin SSP :)
if (spWebApp.Sites[0].RootWeb.WebTemplate == "OSRV")
{
ServerContext SSP = ServerContext.GetContext(spWebApp.Sites[0]);
}
So the code in total looks like this :
SPFarm farm = SPFarm.Local;
SPWebService service = farm.Services.GetValue<SPWebService>("");
foreach (SPWebApplication spWebApp in service.WebApplications)
{
if (spWebApp.Properties.ContainsKey("Microsoft.Office.Server.SharedResourceProvider"))
{
if (spWebApp.Sites[0].RootWeb.WebTemplate == "OSRV")
{
ServerContext SSP = ServerContext.GetContext(spWebApp.Sites[0]);
}
}
}
Hope this helps someone ;)