Condividi tramite


SPWebService class

Represents a Web service that contains one or more Web applications. This Web service allows a Web browser to access the content in SharePoint sites.

Inheritance hierarchy

System.Object
  Microsoft.SharePoint.Administration.SPAutoSerializingObject
    Microsoft.SharePoint.Administration.SPPersistedObject
      Microsoft.SharePoint.Administration.SPPersistedUpgradableObject
        Microsoft.SharePoint.Administration.SPService
          Microsoft.SharePoint.Administration.SPWebService

Namespace:  Microsoft.SharePoint.Administration
Assembly:  Microsoft.SharePoint (in Microsoft.SharePoint.dll)

Syntax

'Declaration
<GuidAttribute("45AD2BF2-4E3E-46A1-B477-126944C0ACEF")> _
<SharePointPermissionAttribute(SecurityAction.LinkDemand, ObjectModel := True)> _
Public NotInheritable Class SPWebService _
    Inherits SPService _
    Implements IBackupRestoreConfiguration, IBackupRestore
'Usage
Dim instance As SPWebService
[GuidAttribute("45AD2BF2-4E3E-46A1-B477-126944C0ACEF")]
[SharePointPermissionAttribute(SecurityAction.LinkDemand, ObjectModel = true)]
public sealed class SPWebService : SPService, 
    IBackupRestoreConfiguration, IBackupRestore

Remarks

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. To return a reference to the current Web service, you can use SPWebService.ContentService.

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

In general, you can get an SPWebService object from the ContentService property. You can also 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.

Examples

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

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
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();
            }
        }
    }
}

Thread safety

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

See also

Reference

SPWebService members

Microsoft.SharePoint.Administration namespace