locked
File Sync Over the Internet RRS feed

  • Question

  • I would like to create an application that can sync files in the following situation.  Several mobile computers will create files to be uploaded to a central file server over an Internet connection from within a Windows Form application.  The files should be synchronized only between the the mobile computer that created the file and the central server.  Is this possible with the sync framework?

    • Moved by Max Wang_1983 Thursday, April 21, 2011 10:19 PM forum consolidation (From:SyncFx - Technical Discussion [ReadOnly])
    Thursday, December 6, 2007 3:51 PM

Answers

  • Hi lwsimpson,

     

    Yes, based on what you have told me the Microsoft Sync Framework would allow you to do the file synchronization you are looking for.  The biggest thing that you will have to implement is the prtocol for communicating the data up to your file servers.

     

    I would recommend that you take a look at the file synchronization whitepaper on our MSDN synchronization developer center as well as the NTFSSample that shows file synchronization in the download of our Microsoft Sync Framework.

     

    Liam

     

     

    Thursday, December 6, 2007 6:59 PM

All replies

  • Hi lwsimpson,

     

    Yes, based on what you have told me the Microsoft Sync Framework would allow you to do the file synchronization you are looking for.  The biggest thing that you will have to implement is the prtocol for communicating the data up to your file servers.

     

    I would recommend that you take a look at the file synchronization whitepaper on our MSDN synchronization developer center as well as the NTFSSample that shows file synchronization in the download of our Microsoft Sync Framework.

     

    Liam

     

     

    Thursday, December 6, 2007 6:59 PM
  • Liam,

     

    I've started where you suggested but I'm stuck on passing the SyncKnowledge via a WCF service. Should I be able to pass this out?

     

    Thanks!

     

    Saturday, December 15, 2007 2:30 AM
  • Quick question to dive deeper: are you stuck on the actual knowledge data transfer over WCF (as in serializing the data and sending over the wire) or the actual data changes themselves? (Obtained from LoadChangeData() or SynchronousDataRetriever::LoadChangeData() 

     

     

    Thanks,

    -Moe

     

    Monday, December 17, 2007 6:00 PM
  • I think the problem is sending it over the wire. Here is my WCF contract so far:

     

    Code Block

    [ServiceContract]
        public interface IRemoteSyncService
        {

            [OperationContract]
            SyncKnowledge GetCurrentSyncKnowledge(string folderPath);

            [OperationContract]
            ChangeBatch GetChanges(string folderPath, ChangeBatch sourceChanges);

            [OperationContract]
            void StoreKnowledgeForScope(string folderPath, SyncKnowledge syncKnowledge, ForgottenKnowledge forgottenKnowledge);
        }

     

     

    The call to GetCurrentSyncKnowledge fails with a WCF communication exception:

     

    InnerException {"The underlying connection was closed: The connection was closed unexpectedly."} System.Exception {System.Net.WebException}

       at System.Net.HttpWebRequest.GetResponse()
       at System.ServiceModel.Channels.HttpChannelFactory.HttpRequestChannel.HttpChannelRequest.WaitForReply(TimeSpan timeout)

     

    Maybe I have something configured wrong or the response is too big, I'm not sure. But if I add a hello world method to the contract I can call that without a problem. So I'm assuming that WCF is having an issue serializing the SyncKnowledge to send over the wire.

     

    Any suggestions?

     

    Thanks!

    Monday, December 17, 2007 6:35 PM
  • I did some more research and came across this post:

    http://netknowledgenow.com/blogs/onmaterialize/archive/2007/03/12/Debugging-WCF-Serialization-issues.aspx

     

    So I added that method and called it and this is the real exception:

     

    Type 'Microsoft.Synchronization.SyncIdFormatGroup' with data contract name 'SyncIdFormatGroup:http://schemas.datacontract.org/2004/07/Microsoft.Synchronization' is not expected. Add any types not known statically to the list of known types - for example, by using the KnownTypeAttribute attribute or by adding them to the list of known types passed to DataContractSerializer.

     

    So I'm going to add that as a known type and see if that fixes it.

     

    Monday, December 17, 2007 7:05 PM
  • Okay I got it working, but because of the weird way you guys are serializing the SyncKnowledge object I have to handle the serialization/deserialization myself. Here is my updated contract:

     

    Code Block

        [ServiceContract(Namespace="http://remotesync/syncservice")]
        public interface IRemoteSyncService
        {
            [OperationContract]
            Message GetCurrentSyncKnowledge(Message request);

            [OperationContract]
            Message GetChanges(Message request);

            [OperationContract]
            void UploadFile(RemoteFileInfo request);

            [OperationContract]
            void DeleteFile(Message request);

            [OperationContract]
            void StoreKnowledgeForScope(Message request);
        }

     

     

    And to send/receive the SyncKnowledge you need to jump through some hoops to get it working:

     

    Code Block

    Message req = Message.CreateMessage(MessageVersion.Soap11, action, folderPath);

     

    List<Type> knownTypes = new List<Type>();
    knownTypes.Add(typeof(SyncIdFormatGroup));
    DataContractSerializer ser = new DataContractSerializer(typeof(SyncKnowledge), knownTypes);

     

    Message rsp = service.GetCurrentSyncKnowledge(req);
    myKnowledge = rsp.GetBody<SyncKnowledge>(ser);

     

     

    I had to do similiar things to get the ChangeBatch across the wire as well. Is this just a CTP issue and somethign that you guys will address in future releases or am I just doing something that wasn't really intended to be done?

     

    Thanks!

     

    BTW - I'm hoping to post the full source code to my blog later this week as an example. Any tips/tricks you can give me before then would be great!

     

     

    Tuesday, December 18, 2007 6:43 PM
  • Okay last post on this subject.

     

    I figured out how to make it work with just a configuration change:

     

    Code Block

      <system.runtime.serialization>
        <dataContractSerializer>
          <declaredTypes>
            <add type="Microsoft.Synchronization.SyncKnowledge, Microsoft.Synchronization, Version=0.94.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91">
              <knownType type="Microsoft.Synchronization.SyncIdFormatGroup, Microsoft.Synchronization, Version=0.94.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91" />
            </add>
          </declaredTypes>
        </dataContractSerializer>
      </system.runtime.serialization>

     

     

    If you add that to both the host and the client config files then it will work without any fancy message deserialization stuff. Just use the parameters as normal.

     

    Thanks!

     

    Wednesday, December 19, 2007 2:15 AM
  • Bryant,

     

    Thanks for your persistence on this and for posting your fix to our forum.  I am sure this will be useful to a number of other people.

     

    Liam

    Wednesday, December 19, 2007 5:06 PM
  • Bryant,

     

    I am interested to see yoru sample. Please, drop me a line when you when you publish it on your blog. I'd like to link to it from my blog.

     

    Thanks

    Thursday, December 20, 2007 10:29 PM
  •  

    I just posted the sample here.

     

    It is still pretty rough but I figured it was better to get it posted now instead of waiting until I had time to add all the features I'd like to add.

     

    I'd love any feedback.

     

    Thanks!

     

    --

    Bryant

    Thursday, January 3, 2008 7:44 PM
  • Bryant,

     

    Thank-you for posting this sample, file sync over the web has been a common request for us so it is very much appreciated that you have shared code this with all of us.  I will certainly be pointing people to this sample in the future.

     

    Liam

     

    Friday, January 4, 2008 12:06 AM
  •  Bryant Likes wrote:

     

    I just posted the sample here.

     

    It is still pretty rough but I figured it was better to get it posted now instead of waiting until I had time to add all the features I'd like to add.

     

    I'd love any feedback.

     

    Thanks!

     

    --

    Bryant

     

    Bryant, I downloaded your sample and stand alone it works great.  However when I try to incorporate it into my actual app, the overridden method GetChangeBatch in RemoteStore.cs is being executed.  In your sample code this method it throws a "not implemented" message.  Simply commenting out the throw doesn't work so I ahve to do something here.

     

    Searches on msdn don't turn anything up for this method, so I am at a loss as to what it is expecting me to do.  Nulling out the parms causes an error during the process. 

     

    Anyone have any ideas on what is needed in this method, or links to explain what this method is trying to accomplish?

    Friday, January 25, 2008 9:41 PM
  • Since you are using the Webservice example, you are going to need to create another function in the webservice that will return everything you need. If you look in the SyncDetails class you will see that it has the GetChangeBatch function. This is great because most of the work is done for you.

     

    One thing to watch out for is that the objects that are passed through "by reference" need to be returned also. You would think that just returning the ChangeBatch object would be enough, but to make it easier you will want to actually return the SyncDetails object from the webservice. Once you get this back you can set the Referenced objects to the correct instances, and you can also access the changebatch and return it to the RemoteStore call.

     

    If you would like more information on this email me at cwilliams@resourcesystems.net .

    Friday, February 8, 2008 4:44 PM