Click to Rate and Give Feedback

  Switch on low bandwidth view
Community Content
In this section
Statistics Annotations (1)
SPWebService Class (Microsoft.SharePoint.Administration)
Represents a Web service that contains one or more Web applications.

Namespace: Microsoft.SharePoint.Administration
Assembly: Microsoft.SharePoint (in microsoft.sharepoint.dll)
Visual Basic (Declaration)
<SharePointPermissionAttribute(SecurityAction.InheritanceDemand, ObjectModel:=True)> _
<SharePointPermissionAttribute(SecurityAction.LinkDemand, ObjectModel:=True)> _
Public NotInheritable Class SPWebService
    Inherits SPService
    Implements IBackupRestore
Visual Basic (Usage)
Dim instance As SPWebService
C#
[SharePointPermissionAttribute(SecurityAction.InheritanceDemand, ObjectModel=true)] 
[SharePointPermissionAttribute(SecurityAction.LinkDemand, ObjectModel=true)] 
public sealed class SPWebService : SPService, IBackupRestore

The SPWebService class is primarily a container for SPWebApplication objects. Use the WebService property of the SPWebApplication class to return the parent Web service of a Web application, and use the WebService property of the SPWebApplicationBuilder class to set the Web service for a new Web application. To return a reference to the current Web service, you can use SPWebService.ContentService.

To return the collection of Web services that are installed within the farm, use the SPWebServiceCollection constructor.

Use an indexer to return a single Web service from the collection. For example, if the collection is assigned to a variable named myWebServices, use myWebServices[index] in C#, or myWebServices(index) in Visual Basic, where index is either the name or the GUID that identifies the Web service.

The following example iterates through all the Web services in a server farm and changes the maximum site count and warning site count of all the content databases used for each Web application.

Visual Basic
Dim webServices As New SPWebServiceCollection(SPFarm.Local)
Dim webService As SPWebService

For Each webService In  webServices
    Dim webApp As SPWebApplication

    For Each webApp In  webService.WebApplications

        If Not webApp.IsAdministrationWebApplication Then

            Dim contentDatabases As SPContentDatabaseCollection = webApp.ContentDatabases
            Dim database As SPContentDatabase

            For Each database In  contentDatabases
                database.WarningSiteCount = 4900
                database.MaximumSiteCount = 5000

                database.Update()
            Next database
        End If
    Next webApp
Next webService
C#
SPWebServiceCollection webServices = new SPWebServiceCollection(SPFarm.Local);

foreach (SPWebService webService in webServices)
{

    foreach (SPWebApplication webApp in webService.WebApplications)
    {

        if (!webApp.IsAdministrationWebApplication)
        {
            SPContentDatabaseCollection contentDatabases = webApp.ContentDatabases;

            foreach (SPContentDatabase database in contentDatabases)
            {
                database.WarningSiteCount = 4900;
                database.MaximumSiteCount = 5000;

                database.Update();
            }
        }
    }
}
Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
Tags What's this?: Add a tag
Community Content   What is Community Content?
Add new content RSS  Annotations
How SPWebService relates to SPServer,SPServiceInstance and SPWebApplication.      Reza Alirezaei - MVP   |   Edit   |   Show History

See community content at http://msdn2.microsoft.com/en-us/library/microsoft.sharepoint.administration.spservercollection.aspx

Reza Alirezaei, MVP
Blog: http://blogs.devhorizon.com/reza

Tags What's this?: Add a tag
Flag as ContentBug
Processing
© 2009 Microsoft Corporation. All rights reserved. Terms of Use  |  Trademarks  |  Privacy Statement
Page view tracker