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.
- Configure a synchronization profile to point to your host and port.
TestDB.GetSynchronizationProfile().ServerName = "localhost";
TestDB.GetSynchronizationProfile().PortNumber = 2480;
- Log in to Unwired Server using a user name and password. This step is required for application initialization.
TestDB.LoginToSync("supAdmin", "s3pAdmin");
- Subscribe to Unwired Server. Unwired Server creates a subscription for this particular application.
- 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");
- 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);
}
- 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();
- Submit the pending changes. The changes are ready for upload, but have not yet been uploaded to the Unwired Server.
- Upload the pending changes to the Unwired Server and get the replay results and all the changed MBO instances.
TestDB.BeginSynchronize(sgs, "mycontext");
- Unsubscribe the device application if the application is no longer used.