}  // Main

        private static void TestCreateConnection(string token, ref PatientRecord record)
        {
            try
            {
                HVConnect.HVConnectClient client  = new HVConnect.HVConnectClient();
                HVConnect.ConnectRequest  request = new HVConnect.ConnectRequest();

                request.Token           = token;
                request.LocalPersonName = record.PatientName;
                request.LocalRecordId   = record.PatientId;
                request.SecretQuestion  = record.SecretQuestion;
                request.SecretAnswer    = record.SecretAnswer;

                HVConnect.ConnectResponse response = client.CreateConnection(request);

                if (response.Success)
                {
                    record.ConnectCode = response.ConnectionCode;
                    record.PickUpURL   = response.PickupUrl;
                    Console.WriteLine("Connection Code = {0}\n", response.ConnectionCode);
                    Console.WriteLine("PickupUrl = {0}\n", response.PickupUrl);
                }
                else
                {
                    Console.WriteLine("Error = {0}\n", response.Message);
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("Exception : CreateConnection : {0}", ex.Message);
                return;
            }
        }
        private static void TestGetValidatedConnections(string token, ref LocalPatientRecords localPatientRecords)
        {
            try
            {
                HVConnect.HVConnectClient             client  = new HVConnect.HVConnectClient();
                HVConnect.ValidatedConnectionsRequest request = new HVConnect.ValidatedConnectionsRequest();

                request.Token     = token;
                request.SinceDate = DateTime.Parse("1/1/1900");

                HVConnect.ValidatedConnectionsResponse response = client.GetValidatedConnections(request);

                if (response.Success)
                {
                    Console.WriteLine("\nValidated HealthVault Account Connections:\n");
                    foreach (HVConnect.ValidatedConnection vc in response.Connections)
                    {
                        if (localPatientRecords.ValidateRecord(vc) == false)
                        {
                            // This record is NOT known to us locally, add the connection to our list.
                            Console.WriteLine("\t**ORPHAN-RECORD: ApplicationID={0}\n\tPatientID={1}\n\tApplicationRecordID={2}\n\tPersonID={3}\n\tRecordID={4}\n",
                                              vc.ApplicationId.ToString(),
                                              vc.ApplicationPatientId,
                                              vc.ApplicationSpecificRecordId,
                                              vc.PersonId.ToString(),
                                              vc.RecordId.ToString());

                            // Add the orphaned record to our list of records.
                            PatientRecord patientRecord = new PatientRecord(vc.ApplicationPatientId, "ORPHAN", "UNKOWN", "UNKNOWN", "UNKNOWN", "UNKOWN", "UNKNOWN", vc.PersonId.ToString(), vc.RecordId.ToString(), vc.ApplicationSpecificRecordId, "validated");
                            localPatientRecords.PatientRecords.Add(patientRecord);
                        }
                        else
                        {
                            // This record is known to us locally, no action needed.
                            Console.WriteLine("\tApplicationID={0}\n\tPatientID={1}\n\tApplicationRecordID={2}\n\tPersonID={3}\n\tRecordID={4}\n",
                                              vc.ApplicationId.ToString(),
                                              vc.ApplicationPatientId,
                                              vc.ApplicationSpecificRecordId,
                                              vc.PersonId.ToString(),
                                              vc.RecordId.ToString());
                        }
                    }
                }
                else
                {
                    Console.WriteLine("Error = {0}\n", response.Message);
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("Exception : GetValidatedConnections : {0}", ex.Message);
                return;
            }
        }
        private static void TestDeletePendingConnection(string token, string localRecordId)
        {
            try
            {
                HVConnect.HVConnectClient client = new HVConnect.HVConnectClient();
                HVConnect.DeletePendingConnectionRequest request = new HVConnect.DeletePendingConnectionRequest();

                request.Token         = token;
                request.LocalRecordId = localRecordId;       // an identifier within local database

                HVConnect.DeletePendingConnectionResponse response = client.DeletePendingConnection(request);
                if (response.Success == false)
                {
                    Console.WriteLine("\nError = {0}\n", response.Message);
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("Exception : DeletePendingConnection : {0}", ex.Message);
                return;
            }
        }
        private static void TestRevokeApplicationConnection(string token, string personId, string recordId)
        {
            try
            {
                HVConnect.HVConnectClient client = new HVConnect.HVConnectClient();
                HVConnect.RevokeApplicationConnectionRequest request = new HVConnect.RevokeApplicationConnectionRequest();

                request.Token    = token;
                request.PersonId = new Guid(personId);
                request.RecordId = new Guid(recordId);

                HVConnect.RevokeApplicationConnectionResponse response = client.RevokeApplicationConnection(request);

                if (response.Success == false)
                {
                    Console.WriteLine("Error = {0}\n", response.Message);
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("Exception : RevokeApplicationConnection : {0}", ex.Message);
                return;
            }
        }