views:

90

answers:

2

I'm researching a way to build an n-tierd sync solution. From the WebSharingAppDemo-CEProviderEndToEnd sample it seems almost feasable however for some reason, the app will only sync if the client has a live SQL db connection. Can some one explain what I'm missing and how to sync without exposing SQL to the internet?

The problem I'm experiencing is that when I provide a Relational sync provider that has an open SQL connection from the client, then it works fine but when I provide a Relational sync provider that has a closed but configured connection string, as in the example, I get an error from the WCF stating that the server did not receive the batch file. So what am I doing wrong?

  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();

....

The error I get occurs in this part of the WCF code:

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;
  }

Any ideas?

A: 

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

Don
A: 

I suppose it's simply a stupid example. It exposes "some" technique but assumes you have to arrange it in proper order by yourself.

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

Arsenty