Answered by:
Sync Framework 2.0 Use WebService to Sync remote Server

Question
-
In Sync Framework 1.0 ,i use
private Dwm.SyncServer.SyncServerProvider _ServerProvider;
private string _connectionString = "Data Source=.;Initial Catalog=SyncSamplesDb;Integrated Security=True";
private DataSet pDs;
[WebMethod]
public SyncServerInfo GetServerInfo(SyncSession session)
{
pDs = Dwm.SyncCommon.DataSetCompressHelper.DecompressDS((byte[])session.SyncParameters["@pDs"].Value);
_ServerProvider = new SyncServerProvider(_connectionString, pDs);
return _ServerProvider.GetServerInfo(session);
}
/// <summary>
/// Access table schema in DataSet form
/// </summary>
/// <param name="tableNames">Table names to bring the schema for</param>
/// <returns>Schema information object</returns>
[WebMethod]
public SyncSchema GetSchema(Collection<string> tableNames, SyncSession session)
{
pDs = Dwm.SyncCommon.DataSetCompressHelper.DecompressDS((byte[])session.SyncParameters["@pDs"].Value);
_ServerProvider = new SyncServerProvider(_connectionString, pDs);
return _ServerProvider.GetSchema(tableNames, session);
}
/// <summary>
/// Enumerate group changes
/// </summary>
/// <param name="groupMetadata">Sync group metadata object</param>
/// <param name="syncSession">Session variables</param>
/// <returns>SyncContext with data table for changes in each sync table in the group</returns>[WebMethod]
public SyncContext GetChanges(SyncGroupMetadata groupMetadata, SyncSession syncSession)
{
pDs = Dwm.SyncCommon.DataSetCompressHelper.DecompressDS((byte[])syncSession.SyncParameters["@pDs"].Value);
_ServerProvider = new SyncServerProvider(_connectionString, pDs);
return _ServerProvider.GetChanges(groupMetadata, syncSession);
}
/// <summary>
/// Apply group changes
/// Soft errors (i.e. Data exceptions and conflicts) are returned in the form of SyncError array.
/// Hard errors are reported via exceptions
/// </summary>
/// <param name="groupMetadata">Sync group metadata object</param>
/// <param name="dataSet">Changes for each table in the group to apply at the server</param>
/// <param name="syncSession">Session variables</param>
/// <returns>SyncContext with sync exceptions and conflicts encountered during application of changes</returns>
[WebMethod]
public SyncContext ApplyChanges(SyncGroupMetadata groupMetadata, DataSet dataSet, SyncSession syncSession)
{
pDs = Dwm.SyncCommon.DataSetCompressHelper.DecompressDS((byte[])syncSession.SyncParameters["@pDs"].Value);
_ServerProvider = new SyncServerProvider(_connectionString, pDs);
return _ServerProvider.ApplyChanges(groupMetadata, dataSet, syncSession);
}
}
but in Sync FrameWork 2.0
public class SyncWebService : System.Web.Services.WebService
{
MySyncProvider provider;
public SyncWebService()
{
}
[WebMethod]
public SyncIdFormatGroup GetIdFormats()
{
return provider.IdFormats;
}
[WebMethod]
public void CreateProviderForSyncSession(string dataAndMetadataFolderPath, string name)
{
this.provider = new MySyncProvider(dataAndMetadataFolderPath, name);
}
[WebMethod]
public void BeginSession()
{
provider.BeginSession();
}
[WebMethod]
public void EndSession()
{
provider.EndSession();
}
[WebMethod]
public ChangeBatch GetChangeBatch(
uint batchSize,
SyncKnowledge destinationKnowledge,
out object changeDataRetriever)
{
object dataRetriever;ChangeBatch changeBatch = provider.GetChangeBatch(
batchSize,
destinationKnowledge,
out dataRetriever);changeDataRetriever = new CachedChangeDataRetriever(
dataRetriever as IChangeDataRetriever,
changeBatch);return changeBatch;
}
[WebMethod]
public FullEnumerationChangeBatch GetFullEnumerationChangeBatch(
uint batchSize,
SyncId lowerEnumerationBound,
SyncKnowledge knowledgeForDataRetrieval,
out CachedChangeDataRetriever changeDataRetriever)
{
object dataRetriever;FullEnumerationChangeBatch changeBatch = provider.GetFullEnumerationChangeBatch(
batchSize,
lowerEnumerationBound,
knowledgeForDataRetrieval,
out dataRetriever);changeDataRetriever = new CachedChangeDataRetriever(
dataRetriever as IChangeDataRetriever,
changeBatch);return changeBatch;
}
[WebMethod]
public void GetSyncBatchParameters(
out uint batchSize,
out SyncKnowledge knowledge)
{
provider.GetSyncBatchParameters(
out batchSize,
out knowledge);
}
[WebMethod]
public byte[] ProcessChangeBatch(
ConflictResolutionPolicy resolutionPolicy,
ChangeBatch sourceChanges,
CachedChangeDataRetriever changeDataRetriever,
byte[] changeApplierInfo)
{
return provider.ProcessRemoteChangeBatch(
resolutionPolicy,
sourceChanges,
changeDataRetriever,
changeApplierInfo);
}
[WebMethod]
public byte[] ProcessFullEnumerationChangeBatch(
ConflictResolutionPolicy resolutionPolicy,
FullEnumerationChangeBatch sourceChanges,
CachedChangeDataRetriever changeDataRetriever,
byte[] changeApplierInfo)
{
return provider.ProcessRemoteFullEnumerationChangeBatch(
resolutionPolicy,
sourceChanges,
changeDataRetriever,
changeApplierInfo);
}#region For demo purpose, not required for RCA pattern
[WebMethod]
public void CleanupTombstones(TimeSpan timespan)
{
provider.CleanupTombstones(timespan);
}
#endregion
}
it can't work,Do AnyOne know how to work in Sync FrameWork through WebService,remember i don't want WCF,only WebService. Thanks
jxfTuesday, March 9, 2010 7:48 AM
Answers
-
am not sure if there's a non-WCF web service sample app out there but you may want to take a look at the WebSharingAppDemo-SqlProviderEndToEnd sample. (http://code.msdn.microsoft.com/sync/Release/ProjectReleases.aspx?ReleaseId=3762) and try convert or follow the pattern to come up with your WebMethods.
If its not too much to ask, any particular reason why WCF is not applicable?
cheers- Marked as answer by Sid Singh [MSFT]Microsoft employee Wednesday, March 24, 2010 7:04 PM
Tuesday, March 9, 2010 12:59 PM
All replies
-
any specific error you're getting? compile time or runtime?
also, your V1 seems to be for the offline scenario, while your V2 is for the peer-to-peer type sync. have you provisioned scopes in your databases?Tuesday, March 9, 2010 8:05 AM -
Yes i have provisioned scopes in your databases,so i want to use the peer-to-peer type sync in V2,i see there is wcf demo ,but i want to webservice(no wcf),Do you have any demo? thanks!
jxfTuesday, March 9, 2010 8:11 AM -
am not sure if there's a non-WCF web service sample app out there but you may want to take a look at the WebSharingAppDemo-SqlProviderEndToEnd sample. (http://code.msdn.microsoft.com/sync/Release/ProjectReleases.aspx?ReleaseId=3762) and try convert or follow the pattern to come up with your WebMethods.
If its not too much to ask, any particular reason why WCF is not applicable?
cheers- Marked as answer by Sid Singh [MSFT]Microsoft employee Wednesday, March 24, 2010 7:04 PM
Tuesday, March 9, 2010 12:59 PM