🚀 Welcome to MDriven Learn –  MDriven is now on Discord!  Don’t miss the latest Release Notes.
WindowsPhone
This page was created by Alexandra on 2018-12-04. Last edited by Wikiadmin on 2026-07-29.

You can use this legacy Windows Phone sample to verify that a Windows Phone client can create and query strongly typed ECO business objects through a WCF persistence service.

What the sample demonstrates

The solution contains three cooperating applications:

Component Role What you verify
WCF persistence server Hosts the persistence service and persists the model objects. It supplies the shared data store for both clients.
WPF client A desktop client for viewing and refreshing the shared data. Objects created on the phone appear here after a refresh.
Windows Phone client A phone-emulator client that creates objects and queries the server. The client uses ECO services to refresh, query, create, and update objects.

The sample is intended to show a shared model: an object created in one client is available to the other client after that client refreshes its data.

Prepare the solution

  1. Open the sample solution supplied with ECO.
  2. If Visual Studio reports projects that cannot be loaded, acknowledge the message and open the solution.
  3. Read the solution ReadMe. It identifies the projects that are intentionally unavailable in the delivered solution.
  4. Remove the unavailable projects from the solution.
  5. Add references to the assemblies supplied in PhoneBuilds.zip. In the reference dialog, choose Browse and select the downloaded assemblies.
  6. Configure the solution startup projects so that the WCF persistence server, WPF client, and Windows Phone client start together.
  7. Start debugging with F5.

Three windows should start. The Windows Phone emulator can take longer than the desktop applications to become available. The WPF application displays data from the shared persistence server; it is not a separate database.

Verify the server endpoint

Before testing the phone client, make sure that its persistence mapper points to the running WCF service. Search the solution for persistenceMapperClient and compare its URI with the service URI defined by the persistence-server project.

For the Windows Phone emulator, localhost refers to the development computer, so a URI such as the following can be valid:

this.persistenceMapperClient1.Uri =
    "http://localhost:52150/EcoProjectWindowsPhone71PMPWCF.svc";

Do not copy the example URI unchanged. Use the URI for your own persistence service. If the client cannot connect, follow WCF troubleshooting, including its guidance for checking the host, service URI, client access policy, and WCF logging.

Use the Windows Phone client

The phone application has two application-bar buttons. Use them in the following order to verify both reading and writing.

Query and refresh data

  1. In the phone application, press the first button, identified by the first X icon at the bottom of the application.
  2. The application refreshes from the persistence service.
  3. It runs a query for Class1 objects that have at least one related Class2 object.
  4. It adds a status line to the phone UI with the total number of Class1 objects and the number that have related Class2 objects.

The query uses the OCL expression Class1.allinstances->select(a|a.Class2->notempty). This means: retrieve all instances of Class1, then retain the instances whose Class2 association is not empty. Learn the expression syntax in OCL.

private void ApplicationBarIconButton_Click(object sender, EventArgs e)
{
    EcoServiceHelper.GetPersistenceService(_ecospace).Refresh(true);

    EcoServiceHelper.GetAsyncSupportService(_ecospace).PerformTaskAsync(new Action(() =>
    {
        IObjectList list = EcoServiceHelper.GetOclPsService(_ecospace).Execute(
            "Class1.allinstances->select(a|a.Class2->notempty)");

        int noOfC1ThatHasC2s = list.Count;
        string extra = "";
        if (list.Count > 0)
            extra = list[0].GetValue<Class1>().Attribute1;

        int noOfC1 = EcoServiceHelper.GetExtentService(_ecospace)
            .AllInstances<Class1>().Count;

        EcoServiceHelper.GetAsyncSupportService(_ecospace).DispatchTaskToMainThread(
            new Action(() =>
            {
                ContentStack.Children.Add(new TextBlock()
                {
                    Text = "db updated, Now C1 Total: " + noOfC1.ToString() +
                           ",\r\n Total of C1 that has C2's " +
                           noOfC1ThatHasC2s.ToString() + " " + extra
                });
            }));
    }));
}

The code uses ECO services obtained from EcoServiceHelper:

Service Use in this example
Persistence service Refreshes the client data from the server with Refresh(true).
Async support service Runs the query away from the UI thread with PerformTaskAsync, then returns to the UI thread with DispatchTaskToMainThread before changing ContentStack.
OCL PS service Executes the OCL query against the persistence service.
Extent service Retrieves all Class1 instances to calculate their total count.

The UI update must run on the main thread. The callback passed to DispatchTaskToMainThread performs that update.

Create and persist an object

  1. Press the other application-bar button.
  2. The application creates a Class1 in the phone client's _ecospace.
  3. It sets Attribute1 to a timestamped message.
  4. It calls UpdateDatabase() to send the change to the persistence server.
private void ApplicationBarIconButton_Click_1(object sender, EventArgs e)
{
    Class1 c1 = new Class1(_ecospace);
    c1.Attribute1 = "Created on WindowsPhone " + DateTime.Now.ToLongTimeString();
    ContentStack.Children.Add(new TextBlock() { Text = "c1 created" });

    _ecospace.UpdateDatabase();
}

Confirm that clients share data

  1. Create a Class1 object in the phone application.
  2. Switch to the WPF application.
  3. Refresh the WPF application.
  4. Confirm that the newly created object is visible.
  5. Create or change data in the WPF application, then use the first phone button to refresh and query again.

If a change is not visible, first verify that both clients use the same WCF persistence-service URI. Then work through WCF issues rather than assuming that a phone-side refresh has changed the server endpoint or persistence configuration.

Scope and current alternatives

This page documents the Windows Phone sample and its WCF-based ECO client behavior. For MDriven development with Xamarin Forms, see Documentation:MDriven In Xamarin. For framework API members beyond the sample code, see API documentation.

See also