1 out of 2 rated this helpful - Rate this topic

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)
public abstract class DomainService : IDisposable

The DomainService type exposes the following members.

  Name Description
Protected method DomainService Initializes a new instance of the DomainService class.
Top
  Name Description
Protected property AuthorizationContext Gets or sets the optional template AuthorizationContext to use for IsAuthorized.
Protected property ChangeSet Gets the current ChangeSet.
Public property Static member Factory Gets or sets the IDomainServiceFactory used to create new DomainService instances.
Protected property ServiceContext Gets the active DomainServiceContext for this DomainService.
Protected property ServiceDescription Gets the DomainServiceDescription for this DomainService.
Protected property ValidationContext Gets or sets the optional ValidationContext to use for all validation operations invoked by the DomainService.
Top
  Name Description
Protected method AuthorizeChangeSet Returns a value that indicates the whether the user is authorized to submit the specified ChangeSet.
Protected method Count<T> Returns the number of rows in an IQueryable.
Public method Dispose() Releases all resources used by the current instance of the DomainService class.
Protected method Dispose(Boolean) Releases all resources used by the current instance of the DomainService class.
Public method Equals (Inherited from Object.)
Protected method ExecuteChangeSet Invokes the DomainOperationEntry for each operation in the ChangeSet.
Protected method Finalize (Inherited from Object.)
Public method GetHashCode (Inherited from Object.)
Public method GetType (Inherited from Object.)
Public method Initialize Initializes this DomainService.
Public method Invoke Invokes the specified operation.
Public method IsAuthorized Requests authorization for the specified DomainOperationEntry.
Protected method MemberwiseClone (Inherited from Object.)
Protected method OnError Called whenever an unrecoverable error occurs during the processing of a DomainService operation.
Protected method PersistChangeSet Finalizes changes after all the operations in the ChangeSet have been invoked.
Public method Query Performs the query operation indicated by the specified QueryDescription.
Public method Submit Performs the operations indicated by the specified ChangeSet by invoking each of the corresponding domain operations.
Public method ToString (Inherited from Object.)
Protected method ValidateChangeSet Validates 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<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.

namespace ExampleNavigationApplication.Web
{
    using System;
    using System.Collections.Generic;
    using System.ServiceModel.DomainServices.Hosting;
    using System.ServiceModel.DomainServices.Server;
    using System.Web.Security;
    using System.Web.Profile;


    [EnableClientAccess()]
    public class RegistrationDomainService : DomainService
    {
        public void AddUser(NewUser user)
        {
            MembershipCreateStatus createStatus;
            Membership.CreateUser(user.UserName, user.Password, user.Email, user.SecurityQuestion, user.SecurityAnswer, true, null, out createStatus);

            if (createStatus != MembershipCreateStatus.Success)
            {
                throw new DomainException(createStatus.ToString());
            }

            ProfileBase profile = ProfileBase.Create(user.UserName, true);
            profile.SetPropertyValue("DefaultRows", user.RecordsToShow);
            profile.Save();
        }

        public IEnumerable<NewUser> GetUsers()
        {
            throw new NotSupportedException();
        }
    }  
}


Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
Did you find this helpful?
(1500 characters remaining)