// Activity

        public Activity CreateActivity(Activity activity, int _logIncidentId = 0, int _logContactId = 0)
        {
            // reuse SR web service
            if (String.IsNullOrWhiteSpace(SRURL) || String.IsNullOrWhiteSpace(SRServiceUsername)
                || String.IsNullOrWhiteSpace(SRServicePassword))
            {
                throw new Exception("Provider's InitForSR not run.");
            }

            string request, response, logMessage, logNote;

            SRSVC.WC_Service_Request_BSClient client = new SRSVC.WC_Service_Request_BSClient(binding, addr);
            MyEndpointBehavior eBehavior = new MyEndpointBehavior();
            client.Endpoint.Behaviors.Add(eBehavior);
            if (ActivityServiceTimeout > 0)
                client.InnerChannel.OperationTimeout = TimeSpan.FromMilliseconds(ActivityServiceTimeout);

            SRSVC.WC_Service_Request_BSInsert_Input ip = new SRSVC.WC_Service_Request_BSInsert_Input();


            ip.ListOfWc_Service_Request_Io = new SRSVC.ListOfWc_Service_Request_IoData();
            ip.ListOfWc_Service_Request_Io.ServiceRequest = new SRSVC.ServiceRequestData[1];
            ip.ListOfWc_Service_Request_Io.ServiceRequest[0] = new SRSVC.ServiceRequestData();
            if (activity.SrID != null)
            {
                ip.ListOfWc_Service_Request_Io.ServiceRequest[0].Id = activity.SrID;
            }
            else
            {
                activity.ErrorMessage = "The following error occurred when doing the Create: SR ID is empty";
                return activity;
            }

            ip.ListOfWc_Service_Request_Io.ServiceRequest[0].ListOfAction = new SRSVC.ListOfActionData();
            ip.ListOfWc_Service_Request_Io.ServiceRequest[0].ListOfAction.Action = new SRSVC.ActionData[1];
            ip.ListOfWc_Service_Request_Io.ServiceRequest[0].ListOfAction.Action[0] = new SRSVC.ActionData();
            if (activity.Comment != null)
            {
                ip.ListOfWc_Service_Request_Io.ServiceRequest[0].ListOfAction.Action[0].Description2 = activity.Description;
                ip.ListOfWc_Service_Request_Io.ServiceRequest[0].ListOfAction.Action[0].Type = activity.ActivityType;
                ip.ListOfWc_Service_Request_Io.ServiceRequest[0].ListOfAction.Action[0].Comment = activity.Comment;
                ip.ListOfWc_Service_Request_Io.ServiceRequest[0].ListOfAction.Action[0].Description2 = activity.Description;
                ip.ListOfWc_Service_Request_Io.ServiceRequest[0].ListOfAction.Action[0].Due = activity.Due;
                ip.ListOfWc_Service_Request_Io.ServiceRequest[0].ListOfAction.Action[0].DueSpecified = true;
                ip.ListOfWc_Service_Request_Io.ServiceRequest[0].ListOfAction.Action[0].Priority = activity.Priority;
                ip.ListOfWc_Service_Request_Io.ServiceRequest[0].ListOfAction.Action[0].Status = activity.Status;
            }

            ip.LOVLanguageMode = "LIC";
            ip.ViewMode = "All";
            Stopwatch stopwatch = new Stopwatch();
            try
            {
                SRSVC.WC_Service_Request_BSInsert_Output op;
                using (new OperationContextScope(client.InnerChannel))
                {
                    MessageHeader usrMsgHdr = MessageHeader.CreateHeader("UsernameToken", "http://siebel.com/webservices", SRServiceUsername);
                    OperationContext.Current.OutgoingMessageHeaders.Add(usrMsgHdr);
                    MessageHeader pwdMsgHdr = MessageHeader.CreateHeader("PasswordText", "http://siebel.com/webservices", SRServicePassword);
                    OperationContext.Current.OutgoingMessageHeaders.Add(pwdMsgHdr);
                    stopwatch.Start();
                    op = client.WC_Service_Request_BSInsert(ip);
                    stopwatch.Stop();
                    request = eBehavior.msgInspector.reqPayload;
                    response = eBehavior.msgInspector.resPayload;

                    SRSVC.ServiceRequestId opData = op.ListOfWc_Service_Request_Io[0];
                    activity.ID = opData.ListOfAction[0].Id;
                }
                logMessage = "Request of creating Activity (Success). Created Activity ID = " + activity.ID;
                logNote = "Request Payload: " + request;
                log.DebugLog(_logIncidentId, _logContactId, logMessage, logNote);

                logMessage = "Response of creating Activity(Success). Created Activity ID = " + activity.ID;
                logNote = "Response Payload: " + response;
                log.DebugLog(_logIncidentId, _logContactId, logMessage, logNote, (int)stopwatch.ElapsedMilliseconds);
            }
            catch (Exception ex)
            {
                request = eBehavior.msgInspector.reqPayload;
                response = eBehavior.msgInspector.resPayload;

                activity.ErrorMessage = "There has been an error communicating with Siebel. Please check log for detail.";

                logMessage = "Request of creating  Activity(Failure). " + ex.Message;
                logNote = "Request Payload: " + request;
                log.ErrorLog(_logIncidentId, _logContactId, logMessage, logNote);

                logMessage = "Response of creating  Activity(Failure). " + ex.Message;
                logNote = "Response Payload: " + response;
                log.ErrorLog(_logIncidentId, _logContactId, logMessage, logNote);

                handleSiebelException(ex, "Create  Activity of Service Request", _logIncidentId, _logContactId);
            }
            return activity;
        }
        // Save Activity to Siebel
        private void SaveActivityToSiebel(string sr_id)
        {
            string logMessage; 

            // check SR status,
            if (checkSRStatus(sr_id) == false)
            {
                return;
            }

            SharedServices.Activity activity = new Activity();
            activity.SrID = sr_id;
            activity.Comment = this._activityControl.InputComment;
            activity.Description = this._activityControl.InputDescription;
            activity.ActivityType = this._activityControl.InputType;
            activity.Due = this._activityControl.InputDue;
            activity.Priority = this._activityControl.InputPriority;
            activity.Status = this._activityControl.InputStatus;

            bool activity_saved;
            try
            {
                // Create Interaction in Siebel
                logMessage = "Ready to propagate activity to Siebel.";
                _log.DebugLog(incidentId: _logIncidentId, logMessage: logMessage);

                activity_saved = activity.Create(_logIncidentId, 0);

            }
            catch (Exception ex)
            {
                logMessage = "Error in Propagating activity." + "SR ID = " + sr_id + "; Exception: " + ex.Message;
                _log.ErrorLog(incidentId: _logIncidentId, logMessage: logMessage);

                activity_saved = false;

                string message = "There has been an error communicating with Siebel. Please check log for detail.";
                MessageBox.Show(message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }

            if (activity_saved == false)
            {
                logMessage = "Activity is not saved in Siebel.  SR ID = " + sr_id + "; Response Error Message: " + activity.ErrorMessage;
                _log.ErrorLog(incidentId: _logIncidentId, logMessage: logMessage);

                MessageBox.Show("There has been an error communicating with Siebel. Please check log for detail.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            else
            {
                logMessage = "Activity is saved in Siebel. ID = " + activity.ID + "; SR ID = " + sr_id;
                _log.DebugLog(incidentId: _logIncidentId, logMessage: logMessage);
            }


        }