Reputation: 13877
I'm trying to ensure that the server I'm currently running a piece of code on is a web front end server. I thought it might be as simple as this:
SPServer.Local.Role.ToString().Equals("WebFrontEnd")
However, if you are running your WFE in addition to app servers, etc on the same box, this will return "Application" and fail to correctly identify it as a web front end.
My idea is that by determining if the Microsoft SharePoint Foundation Workflow Web Application (service) is started and running on the server. This can be determined by going to Central Admin > System Settings > Manage Services on Server.
I need to do this programatically in C#. I'm fairly sure that these services and their statuses can be obtained via powershell which is a viable solution, but I'm not sure how to do it either way.
EDIT -- I'm aware of a way to loop through "services" using the following code:
SPServiceCollection services = SPFarm.Local.Services;
foreach (SPService service in services) {
}
However, this includes some items that look suspiciously similar to the list under "Services on Server" but are all listed with a status of "Online" and dont seem to include this.
Upvotes: 3
Views: 1854
Reputation: 1325
Unfortunately not even that is reliable, as the Foundation Web Application service can be running on servers that are not actually front end servers (i.e. the load balancer never directs traffic to them). Ultimately it is the list of servers that the load balancing mechanism has that determines which servers are true front ends, and because there's various types of load balancers and no single interface to all of them I don't believe there is any one guaranteed method of determining the number of true web front ends in a farm.
Upvotes: 0
Reputation: 50114
I'm not on a machine to check, but I've a feeling you'll have more luck with SPServer.Local.ServiceInstances
- that sounds like it should give the services on the server in particular rather than the farm in general.
Upvotes: 4