public Note CreateNoteAttachment(Note note, int _logIncidentId = 0, int _logContactId = 0)
        {
            if (String.IsNullOrWhiteSpace(NoteURL) || String.IsNullOrWhiteSpace(NoteServiceUsername) || String.IsNullOrWhiteSpace(NoteServicePassword))
            {
                throw new Exception("Provider's InitForSR not run.");
            }

            string request, response, logMessage, logNote;

            ActivityRef.ActivityWSPortClient client = new ActivityRef.ActivityWSPortClient(binding, addr);
            MyEndpointBehavior eBehavior = new MyEndpointBehavior();
            client.Endpoint.Behaviors.Add(eBehavior);
            if(NoteServiceTimeout > 0)
                client.InnerChannel.OperationTimeout = TimeSpan.FromMilliseconds(NoteServiceTimeout );

            ActivityRef.ActivityUpdateMSO_Input ip = new ActivityRef.ActivityUpdateMSO_Input();


            ip.ListOfActivity = new ActivityRef.Activity[1];
            ip.ListOfActivity[0] = new ActivityRef.Activity();

            if (note.NoteID != null)
            {
                ip.ListOfActivity[0].Id = note.NoteID;
            }
            else
            {
                note.ErrorMessage = "There is no Activity ID.";
                return note;
            }

            if (note.SrID != null)
            {
                ip.ListOfActivity[0].ServiceRequestId = note.SrID;
            }
            else
            {
                note.ErrorMessage = "There is no Service Request ID.";
                return note;
            }

            if (note.Content != null)
            {
                ip.ListOfActivity[0].ListOfRelatedAttachment = new ActivityRef.RelatedAttachment[1];
                ip.ListOfActivity[0].ListOfRelatedAttachment[0] = new ActivityRef.RelatedAttachment();
                ip.ListOfActivity[0].ListOfRelatedAttachment[0].FileName = "Chat Transcript From RNow - " + note.Created.Ticks.ToString();
                ip.ListOfActivity[0].ListOfRelatedAttachment[0].FileExt = "txt";
                ip.ListOfActivity[0].ListOfRelatedAttachment[0].ActivityId = note.NoteID;
                var plainContent = System.Text.Encoding.UTF8.GetBytes(note.Content);
                ip.ListOfActivity[0].ListOfRelatedAttachment[0].Attachment = plainContent;
            }
            else
            {
                note.ErrorMessage = "There is no content to save.";
                return note;
            }
            Stopwatch stopwatch = new Stopwatch();
            try
            {
                ActivityRef.ActivityUpdateMSO_Output op;
                using (new OperationContextScope(client.InnerChannel))
                {
                    MessageHeader usrMsgHdr = MessageHeader.CreateHeader("UsernameToken", "http://siebel.com/webservices", NoteServiceUsername);
                    OperationContext.Current.OutgoingMessageHeaders.Add(usrMsgHdr);
                    MessageHeader pwdMsgHdr = MessageHeader.CreateHeader("PasswordText", "http://siebel.com/webservices", NoteServicePassword);
                    OperationContext.Current.OutgoingMessageHeaders.Add(pwdMsgHdr);
                    stopwatch.Start();
                    op = client.ActivityUpdateMSO(ip);
                    stopwatch.Stop();
                    request = eBehavior.msgInspector.reqPayload;
                    response = eBehavior.msgInspector.resPayload;

                    ActivityRef.Activity[] opData = op.ListOfActivity;
                    note.NoteID = opData[0].Id;
                }

                logMessage = "Request of adding attachment to Note (Success). Updated Note ID = " + note.NoteID;
                logNote = "Request Payload: " + request;
                log.DebugLog(_logIncidentId, _logContactId, logMessage, logNote);

                logMessage = "Response of adding attachment to Note (Success). Updated Note ID = " + note.NoteID;
                logNote = "Response Payload: " + response;
                log.DebugLog(_logIncidentId, _logContactId, logMessage, logNote, (int)stopwatch.ElapsedMilliseconds);
            }
            catch (Exception ex)
            {
                request = eBehavior.msgInspector.reqPayload;
                response = eBehavior.msgInspector.resPayload;

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

                logMessage = "Request of dding attachment to Note (Failure). " + ex.Message;
                logNote = "Request Payload: " + request;
                log.ErrorLog(_logIncidentId, _logContactId, logMessage, logNote);

                logMessage = "Response of dding attachment to Note (Failure). " + ex.Message;
                logNote = "Response Payload: " + response;
                log.ErrorLog(_logIncidentId, _logContactId, logMessage, logNote);

                handleSiebelException(ex, "Add attchment to Note", _logIncidentId, _logContactId);
            }
            return note;
        }
        public Note CreateNote(Note note, int _logIncidentId = 0, int _logContactId = 0)
        {
            if (String.IsNullOrWhiteSpace(NoteURL) || String.IsNullOrWhiteSpace(NoteServiceUsername) || String.IsNullOrWhiteSpace(NoteServicePassword))
            {
                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(NoteServiceTimeout > 0)
                client.InnerChannel.OperationTimeout = TimeSpan.FromMilliseconds(NoteServiceTimeout );

            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 (note.SrID != null)
            {
                ip.ListOfWc_Service_Request_Io.ServiceRequest[0].Id = note.SrID;
            }
            else
            {
                note.ErrorMessage = "The following error occurred when doing the Create: SR ID is empty";
                return note;
            }

            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 (note.Content != null)
            {
                ip.ListOfWc_Service_Request_Io.ServiceRequest[0].ListOfAction.Action[0].Description2 = note.Summary;
                ip.ListOfWc_Service_Request_Io.ServiceRequest[0].ListOfAction.Action[0].Type = note.Channel;
                ip.ListOfWc_Service_Request_Io.ServiceRequest[0].ListOfAction.Action[0].Comment = note.Content;
                ip.ListOfWc_Service_Request_Io.ServiceRequest[0].ListOfAction.Action[0].Private = note.Status;
                ip.ListOfWc_Service_Request_Io.ServiceRequest[0].ListOfAction.Action[0].PrivateSpecified = true;
                //ip.ListOfWc_Service_Request_Io.ServiceRequest[0].ListOfAction.Action[0].TypeName = "Notes";
            }



            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", NoteServiceUsername);
                    OperationContext.Current.OutgoingMessageHeaders.Add(usrMsgHdr);
                    MessageHeader pwdMsgHdr = MessageHeader.CreateHeader("PasswordText", "http://siebel.com/webservices", NoteServicePassword);
                    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];
                    note.NoteID = opData.ListOfAction[0].Id;
                }
                logMessage = "Request of creating Note (Success). Created Note ID = " + note.NoteID;
                logNote = "Request Payload: " + request;
                log.DebugLog(_logIncidentId, _logContactId, logMessage, logNote);

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

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

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

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

                handleSiebelException(ex, "Create Note of Service Request", _logIncidentId, _logContactId);
            }
            return note;
        }