Export (0) Print
Expand All

DomainService Class

WCF RIA Services

[WCF RIA Services Version 1 Service Pack 2 is compatible with either .NET framework 4 or .NET Framework 4.5, and with either Silverlight 4 or Silverlight 5.]

Provides a base class for all DomainService implementations.

Namespace:  System.ServiceModel.DomainServices.Server
Assembly:  System.ServiceModel.DomainServices.Server (in System.ServiceModel.DomainServices.Server.dll)

'Declaration
Public MustInherit Class DomainService _
	Implements IDisposable
'Usage
Dim instance As DomainService

The DomainService type exposes the following members.

  NameDescription
Protected methodDomainServiceInitializes a new instance of the DomainService class.
Top

  NameDescription
Protected propertyAuthorizationContextGets or sets the optional template AuthorizationContext to use for IsAuthorized.
Protected propertyChangeSetGets the current ChangeSet.
Public propertyStatic memberFactoryGets or sets the IDomainServiceFactory used to create new DomainService instances.
Protected propertyServiceContextGets the active DomainServiceContext for this DomainService.
Protected propertyServiceDescriptionGets the DomainServiceDescription for this DomainService.
Protected propertyValidationContextGets or sets the optional ValidationContext to use for all validation operations invoked by the DomainService.
Top

  NameDescription
Protected methodAuthorizeChangeSetReturns a value that indicates the whether the user is authorized to submit the specified ChangeSet.
Protected methodCount(Of T)Returns the number of rows in an IQueryable.
Public methodDisposeReleases all resources used by the current instance of the DomainService class.
Protected methodDispose(Boolean)Releases all resources used by the current instance of the DomainService class.
Public methodEquals (Inherited from Object.)
Protected methodExecuteChangeSetInvokes the DomainOperationEntry for each operation in the ChangeSet.
Protected methodFinalize (Inherited from Object.)
Public methodGetHashCode (Inherited from Object.)
Public methodGetType (Inherited from Object.)
Public methodInitializeInitializes this DomainService.
Public methodInvokeInvokes the specified operation.
Public methodIsAuthorizedRequests authorization for the specified DomainOperationEntry.
Protected methodMemberwiseClone (Inherited from Object.)
Protected methodOnErrorCalled whenever an unrecoverable error occurs during the processing of a DomainService operation.
Protected methodPersistChangeSetFinalizes changes after all the operations in the ChangeSet have been invoked.
Public methodQueryPerforms the query operation indicated by the specified QueryDescription.
Public methodSubmitPerforms the operations indicated by the specified ChangeSet by invoking each of the corresponding domain operations.
Public methodToString (Inherited from Object.)
Protected methodValidateChangeSetValidates the whole ChangeSet before calling ExecuteChangeSet.
Top

Domain services are Windows Communication Foundation (WCF) services that encapsulate the business logic of an application. A domain service exposes a set of related operations in the form of a service layer. When you create an instance of a domain service, you specify the data operations that are permitted through the domain service.

The DomainService class is the base class for all classes that serve as domain services. The LinqToEntitiesDomainService(Of TContext) class derives from the DomainService class and is used when interacting with LINQ to Entities models.

A domain service class must be marked with the EnableClientAccessAttribute attribute to make the service available to the client project. The EnableClientAccessAttribute attribute is automatically applied to a domain service when you select the Enable client access check box in the Add New Domain Service Class dialog box.

For more information, see Domain Services.

The following example shows a domain service that exposes an operation for registering a new user. The GetUsers method must be included to ensure that the NewUser entity class is generated for the client project.

Option Compare Binary
Option Infer On
Option Strict On
Option Explicit On

Imports System
Imports System.Collections.Generic
Imports System.ComponentModel
Imports System.ComponentModel.DataAnnotations
Imports System.Linq
Imports System.ServiceModel.DomainServices.Hosting
Imports System.ServiceModel.DomainServices.Server
Imports System.Web.Profile

<EnableClientAccess()>  _
Public Class RegistrationDomainService
    Inherits DomainService

    Public Sub AddUser(ByVal user As NewUser)
        Dim createStatus As MembershipCreateStatus
        Membership.CreateUser(user.UserName, user.Password, user.Email, user.SecurityQuestion, user.SecurityAnswer, True, Nothing, createStatus)

        If (createStatus <> MembershipCreateStatus.Success) Then
            Throw New DomainException(createStatus.ToString())
        End If

        Dim profile = ProfileBase.Create(user.UserName, True)
        profile.SetPropertyValue("DefaultRows", user.RecordsToShow)
        profile.Save()
    End Sub

    Public Function GetUsers() As IEnumerable(Of NewUser)
        Throw New NotSupportedException()
    End Function
End Class


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