public ServiceRequest CreateSR(ServiceRequest sr, int _logIncidentId = 0, int _logContactId = 0) { 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 (SRServiceTimeout > 0) client.InnerChannel.OperationTimeout = TimeSpan.FromMilliseconds(SRServiceTimeout ); 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 (sr.Summary != null) { ip.ListOfWc_Service_Request_Io.ServiceRequest[0].Description = sr.Summary; } else { ip.ListOfWc_Service_Request_Io.ServiceRequest[0].Description = String.Empty; } if (sr.IncidentID != null || sr.IncidentRef != null) { ip.ListOfWc_Service_Request_Io.ServiceRequest[0].IntegrationId = sr.IncidentID + "," + sr.IncidentRef; } if (sr.ContactID != null) { ip.ListOfWc_Service_Request_Io.ServiceRequest[0].ContactId = sr.ContactID; } else { ip.ListOfWc_Service_Request_Io.ServiceRequest[0].ContactId = String.Empty; } if (sr.Severity != null) { ip.ListOfWc_Service_Request_Io.ServiceRequest[0].Severity = sr.Severity; } else { ip.ListOfWc_Service_Request_Io.ServiceRequest[0].Severity = String.Empty; } if (sr.RequestType != null) { ip.ListOfWc_Service_Request_Io.ServiceRequest[0].SRType = sr.RequestType; } else { ip.ListOfWc_Service_Request_Io.ServiceRequest[0].SRType = String.Empty; } if (sr.SerialNumber != null) { ip.ListOfWc_Service_Request_Io.ServiceRequest[0].SerialNumber = sr.SerialNumber; } else { ip.ListOfWc_Service_Request_Io.ServiceRequest[0].SerialNumber = String.Empty; } if (sr.Status != null) { ip.ListOfWc_Service_Request_Io.ServiceRequest[0].Status = sr.Status; } else { ip.ListOfWc_Service_Request_Io.ServiceRequest[0].Status = String.Empty; } if (sr.OwnerID != null) { ip.ListOfWc_Service_Request_Io.ServiceRequest[0].OwnedById = sr.OwnerID; } else { ip.ListOfWc_Service_Request_Io.ServiceRequest[0].OwnedById = String.Empty; } if (sr.RnowHost != null) { ip.ListOfWc_Service_Request_Io.ServiceRequest[0].IntegrationSite = sr.RnowHost; } else { ip.ListOfWc_Service_Request_Io.ServiceRequest[0].IntegrationSite = String.Empty; } 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]; sr.RequestID = opData.Id; } logMessage = "Request of creating Service Request (Success). Created SR ID: " + sr.RequestID; logNote = "Request Payload: " + request; log.DebugLog(_logIncidentId, _logContactId, logMessage, logNote); logMessage = "Response of creating Service Request (Success). Created SR ID: " + sr.RequestID; logNote = "Response Payload: " + response; log.DebugLog(_logIncidentId, _logContactId, logMessage, logNote, (int)stopwatch.ElapsedMilliseconds); } catch (Exception ex) { request = eBehavior.msgInspector.reqPayload; response = eBehavior.msgInspector.resPayload; sr.ErrorMessage = "There has been an error communicating with Siebel. Please check log for detail."; logMessage = "Request of creating Service Request (Failure). " + ex.Message; logNote = "Request Payload: " + request; log.ErrorLog(_logIncidentId, _logContactId, logMessage, logNote); logMessage = "Response of creating Service Request (Failure). " + ex.Message; logNote = "Response Payload: " + response; log.ErrorLog(_logIncidentId, _logContactId, logMessage, logNote); handleSiebelException(ex, "Create Service Request", _logIncidentId, _logContactId); } return sr; }
// 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; }