Configuring an Application to Synchronize and Retrieve MBO Data

This example illustrates the basic code requirements for connecting to Unwired Server, updating mobile business object (MBO) data, and synchronizing the device application from a Client Object API based device application.

  1. Configure a synchronization profile to point to your host and port.
    TestDB.GetSynchronizationProfile().ServerName = "localhost";
    TestDB.GetSynchronizationProfile().PortNumber = 2480;
  2. Log in to Unwired Server using a user name and password. This step is required for application initialization.
    TestDB.LoginToSync("supAdmin", "s3pAdmin");
  3. Subscribe to Unwired Server. Unwired Server creates a subscription for this particular application.
    TestDB.Subscribe();
  4. Synchronize with Unwired Server. Synchronization uploads all the local changes and downloads new data with related subscriptions.
    GenericList<ISynchronizationGroup> sgs = new GenericList<ISynchronizationGroup>();
    sgs.Add(TestDB.GetSynchronizationGroup("default"));
    TestDB.BeginSynchronize(sgs, "mycontext");
  5. List all customer MBO instances from the local database using an object query. FindAll is a pre-defined object query.
    List<Customer> customers = Customer.FindAll();
    foreach (Customer customer in customers)
    {
      Console.WriteLine("customer: " + customer.Fname + " " + customer.Lname + " " + customer.Id  + customer.City);
    }
  6. Find and update a particular MBO instance, and save to the local database.
    Customer cust = Customer.FindByPrimaryKey(441);
    cust.Address = "1 Sybase Dr.";
    cust.Phone = "9252360000"; 
    cust.Save();
  7. Submit the pending changes. The changes are ready for upload, but have not yet been uploaded to the Unwired Server.
    cust.SubmitPending();
  8. Upload the pending changes to the Unwired Server and get the replay results and all the changed MBO instances.
    TestDB.BeginSynchronize(sgs, "mycontext");
  9. Unsubscribe the device application if the application is no longer used.
    TestDB.Unsubscribe();