private static LeadServiceClient connectToService()
        {
            try
            {
                // "wsHttpBinding" is the name of the client endpoint found in app.config
                // client endpoints are auto-gernerated when importing the service reference
                client = new LeadServiceClient("wsHttpBinding");
                //ServicePointManager.ServerCertificateValidationCallback = CertificatePolicy.CertificateValidationCallBack;

                client.ClientCredentials.UserName.UserName = "******";
                client.ClientCredentials.UserName.Password = "******";
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }

            return client;
        }
        private static void OnTimedEvent(object source, ElapsedEventArgs e)
        {
            CallOutcomeSubmission los = new CallOutcomeSubmission();
            client = connectToService();
            //            actionList = client.GetLookupList("ActionTypes");

            submissionTimer.Enabled = false;
            try
            {
                using (var context = new CallOutcomeContext())
                {
                    string[] _testFranchiseIDs = { "1050", "1417", "1240", "2157", "1473", "2340", "2215", "2270", "2336", "2153", "9999" };
                    DateTime tenDaysAgo = DateTime.Now.AddHours(-240);
                    var queryLead = from co in context.T_MollyMaidCallOutcome
                                    join ca in context.T_Call on co.CallID equals ca.CallID
                                    join cp in context.T_Company on ca.CompanyID equals cp.CompanyID
                                    join lv in context.T_LeadVendorEmailHeader on co.LeadVendorEmailID equals lv.LeadVendorEmailID into oj
                                    from sublv in oj.DefaultIfEmpty()
                                    where co.EnteredOn > tenDaysAgo && co.MollyMaidLeadActionID == null
                                        && _testFranchiseIDs.Contains(cp.FranchiseID)  // remove this line to send info for all franchises
                                    select new
                                    {
                                        co.CallOutcomeID,
                                        co.CallID,
                                        co.LeadVendorEmailID,
                                        MollyMaidLeadID = (sublv == null ? String.Empty : sublv.email_text),
                                        ca.OutcomeID,
                                        cp.FranchiseID,
                                        co.MollyMaidLeadActionID,
                                        co.LeadAction,
                                        co.ProcessedOn
                                    };

                    // if any results found for query attempt to send result to Molly Maid
                    if (queryLead.Any())
                    {
                        foreach (var call in queryLead.ToList())
                        {
                            // if the franchsie exists on Molly Maid database
                            if (client.FranchiseExists(int.Parse(call.FranchiseID)))
                            {
                                los.eventLog.WriteEntry("CallOutcomeSubmission.OnTimedEvent: Call ID " + call.CallID + " found with result of " + call.OutcomeID);

                                // if LeadVendorEmailID found then process as lead
                                if (call.LeadVendorEmailID.Value > 0)
                                {
                                    // Get the specific call for updating
                                    var _leadCall = context.T_MollyMaidCallOutcome.Find(call.CallOutcomeID);

                                    _leadCall.MollyMaidLeadActionID = SubmitOutcomeFromLead(los, context, call.CallOutcomeID, call.OutcomeID,
                                                                                        Convert.ToInt32(call.LeadVendorEmailID), int.Parse(call.MollyMaidLeadID));
                                    _leadCall.LeadAction = ACTION_TYPE_CALL_ATTEMPT;
                                    _leadCall.ProcessedOn = DateTime.Now;
                                }

                                // if LeadvendorEmailID = -1 then this is a inbound call
                                else if (call.LeadVendorEmailID.Value == -1)
                                {
                                    // Get the specific call for updating
                                    var _leadCall = context.T_MollyMaidCallOutcome.Find(call.CallOutcomeID);

                                    _leadCall.MollyMaidLeadActionID = SubmitOutcomeFromNewCall(los, context, call.CallOutcomeID, call.OutcomeID);
                                    _leadCall.LeadAction = ACTION_TYPE_CALL_ATTEMPT;
                                    _leadCall.ProcessedOn = DateTime.Now;
                                }

                                // if LeadVendorEmailID is null or 0 then something screwed up
                                else
                                {
                                    los.eventLog.WriteEntry("CallOutcomeSubmission.OnTimedEvent: Call with OutcomeID " + call.OutcomeID.ToString() + ", not processed correctly");
                                }  // end switch

                            }

                            // if no franchsie found
                            else
                            {
                                los.eventLog.WriteEntry("CallOutcomeSubmission.OnTimedEvent: No franchise found with franchise ID " + call.FranchiseID);
                            }

                            // Save any changes currently on context
                            context.SaveChanges();

                        }  // end foreach

                    }
                    // if no results found from query write system log stating such
                    else
                    {
                        // los.eventLog.WriteEntry("CallOutcomeSubmission.OnTimedEvent: No new entries found");
                    }

                }  // end using

                client.Close();
            }

            catch (System.TimeoutException exception)
            {
                los.eventLog.WriteEntry("CallOutcomeSubmission.OnTimedEvent:" + exception.ToString());
                client.Abort();
            }
            catch (System.ServiceModel.CommunicationException exception)
            {
                los.eventLog.WriteEntry("CallOutcomeSubmission.OnTimedEvent:" + exception.ToString());
                client.Abort();
            }
            finally
            {
                submissionTimer.Enabled = true;
            }
        }