How to: Configure N-Tier Synchronization

This topic shows you how to configure N-tier synchronization for Sync Services for ADO.NET. The examples in this topic focus on the following Sync Services types:

For information about how to run sample code, see "Example Applications in the How to Topics" in Programming Common Client and Server Synchronization Tasks.

Understanding N-Tier Synchronization

In an N-tier synchronization architecture, synchronization components are spread across multiple tiers, as shown in the following illustration.

N 层同步拓扑

In a two-tier architecture, all components reside on the client, and the client communicates directly with the server. In an N-tier architecture, the server synchronization provider resides on the server or another tier, and communication between the tiers is handled by the ServerSyncProviderProxy object and a service, such as a Windows Communication Foundation (WCF) service. One of the strengths of Sync Services is the ease with which you can move code from a two-tier architecture to an N-tier architecture. If the code is factored appropriately, after you create a service and add a proxy, only a small change to synchronization agent code is required. Client and server synchronization providers do not have to be changed.

Example

The following code examples show the main components that are involved in an N-tier architecture. Additional WCF components are required. These components are generated for you if you use Visual Studio 2008. For more information, see the Visual Studio documentation.

Key Parts of the API

This section provides code examples that demonstrate the similarities between two-tier and N-tier synchronization, and point out the key parts of the API to use when you are configuring N-tier synchronization. The following code example is from a class that derives from SyncAgent. For two-tier synchronization, the client provider and server provider are both referenced directly in the synchronization agent as local and remote providers.

The following code example references the client provider directly, as in the two-tier example. However, the remote provider now references a proxy instead of directly referencing the server provider. The proxy is created by passing a reference to a WCF service.

The following code examples create client and server providers. This code is identical whether a two-tier or N-tier architecture is used.

The following code example creates an interface that the service implements. The interface includes the four key methods of the server provider.

The following code example creates a service. This service implements the interface that was created in the previous code example and references the server provider.

请参阅

其他资源

Programming Common Client and Server Synchronization Tasks