0

我正在研究一种构建 n 层同步解决方案的方法。从 WebSharingAppDemo-CEProviderEndToEnd 示例来看,它似乎几乎是可行的,但由于某种原因,该应用程序只有在客户端具有实时 SQL 数据库连接时才会同步。有人可以解释我缺少什么以及如何在不将 SQL 暴露到 Internet 的情况下进行同步吗?

我遇到的问题是,当我提供一个具有来自客户端的开放 SQL 连接的关系同步提供程序时,它可以正常工作,但是当我提供一个具有关闭但已配置的连接字符串的关系同步提供程序时,如示例中所示,我从 WCF 收到一条错误消息,指出服务器没有收到批处理文件。那么我做错了什么?

  SqlConnectionStringBuilder builder = new SqlConnectionStringBuilder();
  builder.DataSource = hostName;
  builder.IntegratedSecurity = true;
  builder.InitialCatalog = "mydbname";
  builder.ConnectTimeout = 1;
  provider.Connection = new SqlConnection(builder.ToString());

  // provider.Connection.Open();  **** un-commenting this causes the code to work**

  //create anew scope description and add the appropriate tables to this scope
  DbSyncScopeDescription scopeDesc = new DbSyncScopeDescription(SyncUtils.ScopeName);

  //class to be used to provision the scope defined above
  SqlSyncScopeProvisioning serverConfig = new SqlSyncScopeProvisioning();

……

我得到的错误发生在这部分 WCF 代码中:

public SyncSessionStatistics ApplyChanges(ConflictResolutionPolicy resolutionPolicy, ChangeBatch sourceChanges, object changeData)
{
  Log("ProcessChangeBatch: {0}", this.peerProvider.Connection.ConnectionString);

  DbSyncContext dataRetriever = changeData as DbSyncContext;

  if (dataRetriever != null && dataRetriever.IsDataBatched)
  {
    string remotePeerId = dataRetriever.MadeWithKnowledge.ReplicaId.ToString();
    //Data is batched. The client should have uploaded this file to us prior to calling ApplyChanges.
    //So look for it.
    //The Id would be the DbSyncContext.BatchFileName which is just the batch file name without the complete path
    string localBatchFileName = null;
    if (!this.batchIdToFileMapper.TryGetValue(dataRetriever.BatchFileName, out localBatchFileName))
    {
      //Service has not received this file. Throw exception
      throw new FaultException<WebSyncFaultException>(new WebSyncFaultException("No batch file uploaded for id " + dataRetriever.BatchFileName, null));
    }
    dataRetriever.BatchFileName = localBatchFileName;
  }

有任何想法吗?

4

2 回答 2

0

For the Batch file not available issue, remove the IsOneWay=true setting from IRelationalSyncContract.UploadBatchFile. When the Batch file size is big, ApplyChanges will be called even before fully completing the previous UploadBatchfile.

// Replace
[OperationContract(IsOneWay = true)]

// with
[OperationContract] void UploadBatchFile(string batchFileid, byte[] batchFile, string remotePeer1

于 2010-03-05T13:01:21.877 回答
0

我想这只是一个愚蠢的例子。它公开了“一些”技术,但假设您必须自己按正确的顺序排列它。

http://msdn.microsoft.com/en-us/library/cc807255.aspx

于 2010-03-29T08:08:53.020 回答