我正在研究一种构建 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;
}
有任何想法吗?