/// <summary> /// Adds logging to the method invocation. /// </summary> /// <param name="invocation"></param> /// <returns> return value of the targetd method</returns> public object Invoke(IMethodInvocation invocation) { IASALog log = ASALogManager.GetLogger(invocation.TargetType); string methodName = invocation.TargetType.ToString() + "." + invocation.Method.Name; StringBuilder arguments = new StringBuilder(); ParameterInfo[] parameterInfos = invocation.Method.GetParameters(); object[] argValues = invocation.Arguments; for (int i = 0; i < parameterInfos.Length; i++) { arguments.Append(parameterInfos[i].Name).Append("=").Append(argValues[i]); if (i < (parameterInfos.Length - 1)) { arguments.Append("; "); } } if (LogEntry) { log.LogMethodEntry(methodName, arguments.ToString()); } object returnValue = null; bool exitThroughException = false; DateTime startTime = DateTime.Now; try { returnValue = invocation.Proceed(); return(returnValue); } catch (Exception e) { if (logException) { log.Error("Exception occured while calling method " + methodName, e); } exitThroughException = true; throw; } finally { if (!exitThroughException && logExit) { TimeSpan executionTime = DateTime.Now - startTime; if (returnValue == null) { log.LogMethodExit(methodName, "", arguments.ToString(), executionTime); } else { log.LogMethodExit(methodName, returnValue.ToString(), arguments.ToString(), executionTime); } } } }
/// <summary> /// This method will be used to add the ASADispatchMessageInspector behavior /// to the Behaviors collection of the ServiceHost’s service description. /// </summary> public void AddCustomMessageInspectorBehavior() { try { //Add Custom Behavior to all services this.Description.Behaviors.Add(new ASADispatchMessageInspector()); } catch (ASAException exASA) { IASALog Log = ASALogManager.GetLogger(typeof(ASAServiceHost)); Log.Error("Couldn't add custom message inspection behavior", exASA); throw new ApplicationException("Couldn't add custom message inspection behavior:" + exASA.Message + " Error_code:" + exASA.ExceptionError_id + " Business Message:" + exASA.BusinessDescription); } catch (Exception ex) { IASALog Log = ASALogManager.GetLogger(typeof(ASAServiceHost)); Log.Error("Couldn't add custom message inspection behavior", ex); throw new ApplicationException("Couldn't add custom message inspection behavior:" + ex.Message); } }
/// <summary> /// Add ASAFaultHandler to the ASAServiceHost /// </summary> public void AddCustomFaultHandling() { try { foreach (ChannelDispatcher dispatcher in this.ChannelDispatchers) { dispatcher.ErrorHandlers.Add(new ASAFaultErrorHandler()); } } catch (ASAException exASA) { IASALog Log = ASALogManager.GetLogger(typeof(ASAServiceHost)); Log.Error("Couldn't add ASAFaultErrorHandler to the ASAServiceHost", exASA); throw new ApplicationException("Couldn't add ASAFaultErrorHandler to the ASAServiceHost:" + exASA.Message + " Error_code:" + exASA.ExceptionError_id + " Business Message:" + exASA.BusinessDescription); } catch (Exception ex) { IASALog Log = ASALogManager.GetLogger(typeof(ASAServiceHost)); Log.Error("Couldn't add ASAFaultErrorHandler to the ASAServiceHost", ex); throw new ApplicationException("Couldn't add ASAFaultErrorHandler to the ASAServiceHost:" + ex.Message); } }
private void AddCustomSchemaValidation() { try { bool validateRequest = Parameters.Instance.EnableASAServiceRequestSchemaValidation; bool validateReply = Parameters.Instance.EnableASAServiceReplySchemaValidation; string messageContractSchemasPath = Parameters.Instance.TargetMessageContractSchemasPath; this.Description.Behaviors.Add(new ASASchemaValidationServiceBehavior(messageContractSchemasPath, validateRequest, validateReply)); } catch (ASAException exASA) { IASALog Log = ASALogManager.GetLogger(typeof(ASAServiceHost)); Log.Error("Couldn't add ASAFaultErrorHandler to the ASAServiceHost", exASA); throw new ApplicationException("Couldn't add ASAFaultErrorHandler to the ASAServiceHost:" + exASA.Message + " Error_code:" + exASA.ExceptionError_id + " Business Message:" + exASA.BusinessDescription); } catch (Exception ex) { IASALog Log = ASALogManager.GetLogger(typeof(ASAServiceHost)); Log.Error("Couldn't add ASAFaultErrorHandler to the ASAServiceHost", ex); throw new ApplicationException("Couldn't add ASAFaultErrorHandler to the ASAServiceHost:" + ex.Message); } }