问题描述
有没有人在这里工作,具有同步框架,并通过WCF终端同步?请分享code样品或样本项目。我专门找下线场景中的客户端上线才从服务器获取更新。
Has anyone here worked with Sync Framework and syncing through WCF endpoints? Please share code samples or sample projects. I am specifically looking for offline scenarios where client comes online only to fetch updates from the Server.
推荐答案
我做了以下获得使用WCF与SQL Server同步框架工作2008
I did the following to get Sync Framework working using WCF with SQL Server 2008
- 在SQL Server中启用更改跟踪2008
- 已启用更改跟踪参与同步的表
- 添加元数据表命名锚
- 添加了一个表来跟踪客户端ID命名为GUID
- 二手SqlEx pressClientSyncProvider可根据无国界医生codePLEX项目现场为客户端同步提供
-
用于SqlSyncAdapterBuilder建立适配器参与同步的表
- Enabled Change Tracking in SQL Server 2008
- Enabled change tracking for tables participating in the Sync
- Added a metadata table named anchor
- Added a table to track client Ids named "guid"
- Used SqlExpressClientSyncProvider available from MSF's codeplex project site as Client Sync Provider
Used SqlSyncAdapterBuilder to build adapters for tables participating in the Sync
foreach (var item in anchorTables)
{
// Use adapter builder to generate T-SQL for querying change tracking data and CRUD
SqlSyncAdapterBuilder builder = new SqlSyncAdapterBuilder();
builder.Connection = new SqlConnection(this.connectionStringFactory.ConnectionString);
builder.ChangeTrackingType = ChangeTrackingType.SqlServerChangeTracking;
builder.SyncDirection = SyncDirection.Bidirectional;
builder.TableName = item.TableName;
// Get sync adapters from builder
SyncAdapter clientAdapter = builder.ToSyncAdapter();
clientAdapter.TableName = item.TableName;
this.clientSyncProvider.SyncAdapters.Add(clientAdapter);
}
添加锚点命令
Added anchor commands
SqlCommand anchroCommand =
new SqlCommand { CommandText = "SELECT @"
+ SyncSession.SyncNewReceivedAnchor
+ " = change_tracking_current_version()" };
anchroCommand.Parameters.Add("@"
+ SyncSession.SyncNewReceivedAnchor, SqlDbType.BigInt)
.Direction = ParameterDirection.Output;
this.clientSyncProvider.SelectNewAnchorCommand = anchroCommand;
使用DbServerSyncProvider充当服务器同步提供程序的情况下实现WCF服务。您将有产生同步适配器,并设置锚命令,如图中的服务器供应商也previous一步。
Implemented a WCF Service using a instance of DbServerSyncProvider functioning as Server sync provider. You will have generate sync adapters and set anchor command as shown in previous step for Server provider too.
[ServiceContract]
public interface ISyncService
{
[OperationContract]
SyncContext ApplyChanges(SyncGroupMetadata groupMetadata, DataSet dataSet, SyncSession syncSession);
[OperationContract]
SyncContext GetChanges(SyncGroupMetadata groupMetadata, SyncSession syncSession);
[OperationContract]
SyncSchema GetSchema(Collection<string> tableNames, SyncSession syncSession);
[OperationContract]
SyncServerInfo GetServerInfo(SyncSession syncSession);
}
创建一个代理类实现ServerSyncProvider访问WCF服务
Created a proxy class implementing ServerSyncProvider to access WCF service
public class DbServerSyncProviderProxy : ServerSyncProvider
{
SyncServiceProxy.SyncServiceClient serviceProxy = new SyncServiceProxy.SyncServiceClient();
public override SyncContext ApplyChanges(SyncGroupMetadata groupMetadata, DataSet dataSet, SyncSession syncSession)
{
return serviceProxy.ApplyChanges(groupMetadata, dataSet, syncSession);
}
}
这篇关于同步的SQL Server 2008数据库通过HTTP使用WCF和放大器;同步框架的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!