Ejemplo n.º 1
0
 public static void AddMissingDefaultDataToTID(ITID tid, MessageHeaders headers, ServiceDescription desc)
 {
     tid.Set(TIDField.MESSAGEID, Guid.NewGuid().ToString());
     tid.Set(TIDField.MESSAGEVERSION, GetMessageVersion(desc));
     tid.Set(TIDField.SERVICENAME, GetServiceName(desc));
     tid.Set(TIDField.OPERATIONNAME, GetOperationName(headers));
 }
Ejemplo n.º 2
0
        /// <summary>
        /// o	GetBeforeSendRequestData():  This method will encapsulate the logic
        /// used to set the TID values appropriately for when a request message is
        /// being sent from the client.  This will call many of the individual field
        /// GetXXX() methods.  [e.g. GetMessageSequenceNumber(), GetServiceName(),
        /// GetExpireDt()]
        /// </summary>
        /// <param name="headers"></param>
        /// <returns></returns>
        public static Hashtable GetBeforeSendRequestData(ITID tid, MessageHeaders headers, IClientChannel channel, ServiceEndpoint svcEndpoint)
        {
            Hashtable mapProps = new Hashtable();

            mapProps[TIDField.MESSAGEVERSION] = GetMessageVersion(svcEndpoint);
            mapProps[TIDField.SERVICENAME]    = GetServiceName(svcEndpoint);
            mapProps[TIDField.OPERATIONNAME]  = GetOperationName(headers);
            //if(OperationContext.Current != null)
            //    mapProps[TIDField.USERNAME] = GetUsername();
            //mapProps[TIDField.MESSAGEID] = GetMessageID(headers);           //<-- this is set by TID.CreateTID()
            //mapProps[TIDField.CORRELATIONID] = GetCorrelationID(headers);   //<-- this is set by TID.CreateTID()
            //mapProps[TIDField.ORIGINATIONDT] = GetOriginationDt(headers);   //<-- this is set by TID.CreateTID()
            //mapProps[TIDField.SENTDT] = GetSentDt(headers);                 //<-- this will be set by TIDFactory.GetSendTID()
            //mapProps[TIDField.RECEIVEDDT] = GetReceivedDt(headers);         //<-- this is set by TID.CreateTID() and again later by GetRecvTID()
            if (OperationContext.Current == null)
            {
                mapProps[TIDField.EXPIREDT] = GetExpireDt((DateTime)tid.Get(TIDField.ORIGINATIONDT), channel.OperationTimeout);
            }
            mapProps[TIDField.MESSAGESEQNUMBER] = GetMessageSequenceNumber(tid);
            mapProps[TIDField.SOURCE]           = GetSendingMessageSource(headers);
            mapProps[TIDField.DESTINATION]      = GetSendingMessageDestination(headers, channel);
            mapProps[TIDField.SYNCH]            = GetSyncFlag(channel, (string)mapProps[TIDField.OPERATIONNAME]);
            mapProps[TIDField.REPLY]            = false;
            mapProps[TIDField.PARAMLIST]        = GetParamList(headers);

            return(mapProps);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// The GetSendTID() static function is used to create a new TID object based on the
        ///  TID version found in the MessageHeaders argument passed to the function.
        /// GetRecvTID() calls GetTIDFromMessage() to create the new TID object based on the MessageHeaders argument.
        /// GetRecvTID() calls RecvTID() on the newly created TID object to set the TID fields.
        /// Update/override any TID fields by specifying those field/values within the passed Hashtable argument.
        /// GetRecvTID() sets the SUCCESS key in the passed Hashtable to the return value of CreateTID (true or false)
        ///  or to false if GetTIDFromMessage() returns null.
        /// </summary>
        /// <param name="messageHeadersIn"></param>
        /// <param name="mapPropsIn"></param>
        /// <returns>ITID</returns>
        public static ITID GetSendTID(ITID tidIn, Hashtable mapPropsIn)
        {
            // Initialize success flag
            mapPropsIn[TIDField.SUCCESS] = true;

            // Create a new TID if not already created
            if (tidIn == null)
            {
                // Set fields for TID creation
                tidIn = GetCreateTID(mapPropsIn);

                // Save success status of GetCreateTID()
                mapPropsIn[TIDField.SUCCESS] = (bool)mapPropsIn[TIDField.SUCCESS];
            }

            // Create the new TID object based on version passed in request rcvd TID (tidIn)
            TIDBase tid = (tidIn.GetVersion() == "01.00.000")   // Add supported versions below
                        ? new TID()
//                      : (tidVersion.TidVersion == "99.99.999")
//                      ? new TID_99_99_999()
                          // keep updated to latest TID version below
                        : new TID();

            // Call SendTID()
            if (!tid.SendTID(tidIn, mapPropsIn))
            {
                // If either GetCreateTID() or SendTID() failed, update success status to false
                mapPropsIn[TIDField.SUCCESS] = false;
            }

            // Return interface to new object
            return(tid);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// o	GetAfterReceiveReplyData():  This method will encapsulate the logic
        /// used to set the TID values appropriately for when a reply message is
        /// being received at the client.  This will call many of the individual
        /// field GetXXX() methods.  [e.g. GetMessageSequenceNumber()]
        /// </summary>
        /// <param name="headers"></param>
        /// <returns></returns>
        public static Hashtable GetAfterReceiveReplyData(ITID tid, MessageHeaders headers)
        {
            Hashtable mapProps = new Hashtable();

            mapProps[TIDField.MESSAGESEQNUMBER] = GetMessageSequenceNumber(tid);

            return(mapProps);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// This will retrieve the ParamList (if there is one) from the message headers
        /// and set that as the ParamList for the TID.
        /// </summary>
        /// <param name="tid"></param>
        /// <param name="headers"></param>
        public static void AddParamListFromMessageToTID(ITID tid, MessageHeaders headers)
        {
            Dictionary <string, string> paramList = GetParamList(headers);

            if (paramList != null)
            {
                tid.Set(TIDField.PARAMLIST, paramList);
            }
        }
Ejemplo n.º 6
0
        /// <summary>
        /// o	GetAfterReceiveRequestData():  This method will encapsulate the logic
        /// used to set the TID values appropriately for when a request message is
        /// being received at the service.
        /// This will call many of the individual field GetXXX() methods.
        /// </summary>
        /// <param name="headers"></param>
        /// <returns></returns>
        public static Hashtable GetAfterReceiveRequestData(ITID tid, MessageHeaders headers, IClientChannel channel)
        {
            Hashtable mapProps = new Hashtable();

            mapProps[TIDField.MESSAGESEQNUMBER] = GetMessageSequenceNumber(tid);
            mapProps[TIDField.DESTINATION]      = GetReceivingMessageDestination(headers, channel);

            return(mapProps);
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Call SendTID() to update the fields within the TID object when a message is being sent.
        /// SendTID() will update the appropriate property and Hashtable entries.
        /// The ITID argument passed must be the interface to the Request received TID (not Reply received TID).
        /// Update/override any TID fields by specifying those field/values within the passed Hashtable argument.
        /// The abstract RecvTID() method must be implemented in any TIDBase-derived class.
        /// </summary>
        /// <param name="tidIn"></param>
        /// <param name="mapPropsIn"></param>
        /// <returns>bool</returns>
        public override bool SendTID(ITID tidIn, Hashtable mapPropsIn)
        {
            bool bRet = true;

            // Ensure reply field is set
            bRet = (mapPropsIn.ContainsKey(TIDField.REPLY) && bRet);

            // Get reply flag -- if not specified (although it is required), assume this is a request message
            bool isReply = (bRet) ? (bool)mapPropsIn[TIDField.REPLY] : false;

            // Get new ParamList if specified by caller in mapPropsIn
            Dictionary <string, string> paramListIn = (mapPropsIn.ContainsKey(TIDField.PARAMLIST))
                ? (Dictionary <string, string>)mapPropsIn[TIDField.PARAMLIST]
                : null;

            // Processing for reply messages
            if (isReply)
            {
                if (paramListIn == null)
                {
                    // If message is a reply and caller did not specify a ParamList in mapPropsIn, use ParamList from received tid (tidIn) instead
                    paramListIn = (Dictionary <string, string>)tidIn.Get(TIDField.PARAMLIST);
                }

                // Reply messages must specify the MESSAGESEQNUMBER when sending messages
                //  since we only have the MESSAGESEQNUMBER from the request received TID (not the reply received TID)
                bRet = (mapPropsIn.ContainsKey(TIDField.MESSAGESEQNUMBER) && bRet);
            }
            // Processing for request messsages
            else
            {
                // Request messages will set the next
                bRet = (Set(TIDField.MESSAGESEQNUMBER, (int)(tidIn.Get(TIDField.MESSAGESEQNUMBER)) + 1) && bRet);
            }

            bRet = (Set(TIDField.CORRELATIONID, tidIn.Get(TIDField.CORRELATIONID)) && bRet);
            bRet = (mapPropsIn.ContainsKey(TIDField.DESTINATION) && bRet);
            bRet = (Set(TIDField.EXPIREDT, tidIn.Get(TIDField.EXPIREDT)) && bRet);
            bRet = (Set(TIDField.MESSAGEID, Guid.NewGuid().ToString()) && bRet);
            bRet = (mapPropsIn.ContainsKey(TIDField.MESSAGEVERSION) && bRet);
            bRet = (mapPropsIn.ContainsKey(TIDField.OPERATIONNAME) && bRet);
            bRet = (Set(TIDField.ORIGINATIONDT, tidIn.Get(TIDField.ORIGINATIONDT)) && bRet);
            bRet = (Set(TIDField.PARAMLIST, paramListIn) && bRet);
            bRet = (Set(TIDField.RECEIVEDDT, null) && bRet);
            bRet = (mapPropsIn.ContainsKey(TIDField.SOURCE) && bRet);
            bRet = (mapPropsIn.ContainsKey(TIDField.SERVICENAME) && bRet);
            bRet = (Set(TIDField.SYNCH, tidIn.Get(TIDField.SYNCH)) && bRet);
            bRet = (Set(TIDField.USERNAME, tidIn.Get(TIDField.USERNAME)) && bRet);
            bRet = (Set(TIDField.SENTDT, DateTime.UtcNow) && bRet);

            // Override any above set fields passed in mapPropsIn
            bRet = (SetFields(mapPropsIn) && bRet);

            return(bRet);
        }
Ejemplo n.º 8
0
 // This method updates the MessageSeqNumber in the IncomingMessage headers so it is
 // up-to-date for things later in the process during the multi-hop scenario.
 private static void WriteMessageSeqNumToIncomingHeaders(int iNewSeqNumber)
 {
     if (OperationContext.Current != null && OperationContext.Current.IncomingMessageHeaders != null)
     {
         MessageHeaders headers = OperationContext.Current.IncomingMessageHeaders;
         ITID           tid     = TIDFactory.GetTIDFromMessage(OperationContext.Current.IncomingMessageHeaders);
         if (tid != null)
         {
             tid.Set(TIDField.MESSAGESEQNUMBER, iNewSeqNumber);
             ASAMessageInspectionHelper.AddTIDHeader(tid, ref headers);
         }
     }
 }
Ejemplo n.º 9
0
        /// <summary>
        /// o	GetBeforeSendReplyData():  This method will encapsulate the logic
        /// used to set the TID values appropriately for when a reply message is
        /// being sent from the service.
        /// This will call many of the individual field GetXXX() methods.
        /// </summary>
        /// <param name="headers"></param>
        /// <returns></returns>
        public static Hashtable GetBeforeSendReplyData(ITID tid, MessageHeaders headers, ServiceDescription desc)
        {
            Hashtable mapProps = new Hashtable();

            mapProps[TIDField.MESSAGEVERSION]   = GetMessageVersion(desc);
            mapProps[TIDField.SERVICENAME]      = GetServiceName(desc);
            mapProps[TIDField.OPERATIONNAME]    = GetOperationName(headers);
            mapProps[TIDField.MESSAGESEQNUMBER] = GetMessageSequenceNumber(tid);

            //for the reply, just swap the Source and Dest:
            mapProps[TIDField.SOURCE]      = (string)tid.Get(TIDField.DESTINATION);
            mapProps[TIDField.DESTINATION] = (string)tid.Get(TIDField.SOURCE);
            mapProps[TIDField.REPLY]       = true;

            return(mapProps);
        }
Ejemplo n.º 10
0
        public static Hashtable GetReplyDataWhenNoTidWasFound(ITID tid, MessageHeaders headers)
        {
            OperationContext ctx     = OperationContext.Current;
            IClientChannel   channel = null;

            if (ctx == null && ctx.Channel is IClientChannel)
            {
                channel = (IClientChannel)ctx.Channel;
            }

            Hashtable mapProps = new Hashtable();

            mapProps[TIDField.MESSAGESEQNUMBER] = ASAMessageInspectionHelper.GetMessageSeqNumberFromIncomingHeaders() + 1;
            ASAMessageInspectionHelper.WriteMessageSeqNumToIncomingHeaders((int)mapProps[TIDField.MESSAGESEQNUMBER]);
            mapProps[TIDField.CORRELATIONID] = ASATIDHelper.GetTIDCorrelationID();
            mapProps[TIDField.OPERATIONNAME] = GetOperationName(headers); // --> try to get from SOAP Action, but will probably be empty.
            mapProps[TIDField.SENTDT]        = DateTime.UtcNow;           //dont' know when it was actually sentin this scenario, so our best guess is "now".

            // desintination = this machine
            mapProps[TIDField.DESTINATION] = GetReceivingMessageDestination(headers, channel);
            // source --> in message?
            mapProps[TIDField.SOURCE] = GetReceivingMessageSource(headers);

            // set reply = true
            // set synch = true
            mapProps[TIDField.SYNCH] = GetSyncFlag(channel, (string)mapProps[TIDField.OPERATIONNAME]);
            mapProps[TIDField.REPLY] = true;

            if (ctx != null)
            {
                mapProps[TIDField.USERNAME] = GetUsername();
            }

            //mapProps[TIDField.MESSAGEID] = GetMessageID(headers);           //<-- this is set by TID.CreateTID()
            //mapProps[TIDField.ORIGINATIONDT] = GetOriginationDt(headers);   //<-- this is set by TID.CreateTID()
            //mapProps[TIDField.RECEIVEDDT] = GetReceivedDt(headers);         //<-- this is set by TID.CreateTID() and again later by GetRecvTID()
            //mapProps[TIDField.MESSAGEVERSION] = GetMessageVersion(svcEndpoint);  //--> no svc endpoint to get this from in context.
            //mapProps[TIDField.SERVICENAME] = GetServiceName(svcEndpoint); //--> no svc endpoint to get this from in context.

            if (OperationContext.Current == null)
            {
                mapProps[TIDField.EXPIREDT] = GetExpireDt((DateTime)tid.Get(TIDField.ORIGINATIONDT), channel.OperationTimeout);
            }

            return(mapProps);
        }
Ejemplo n.º 11
0
        /// <summary>
        /// AddTIDHeader():  This method will be used to add TID information to the
        /// MessageHeaders collection passed in.  (If a TID already exists in the headers collection,
        /// this method will remove it, and replace it with the TID data being passed.)
        /// </summary>
        /// <param name="tid"></param>
        /// <param name="headers"></param>
        /// <returns></returns>
        public static bool AddTIDHeader(ITID tid, ref MessageHeaders headers)
        {
            bool bAdded = false;

            if (headers != null && tid != null)
            {
                //this will remove 'tid' from the header if its already in there.. we don't want it added twice.
                RemoveTIDHeader(tid, ref headers);

                MessageHeader <TIDBase> mhMessageTID = new MessageHeader <TIDBase>((TIDBase)tid);
                headers.Add(mhMessageTID.GetUntypedHeader("TID", "TID"));

                bAdded = true;
            }

            return(bAdded);
        }
Ejemplo n.º 12
0
        /// <summary>
        /// RemoveTIDHeader():  This method will be used to remove TID information
        /// from the MessageHeaders collection passed in.
        /// </summary>
        /// <param name="tid"></param>
        /// <param name="headers"></param>
        /// <returns></returns>
        public static bool RemoveTIDHeader(ITID tid, ref MessageHeaders headers)
        {
            bool bRemoved = false;

            if (tid != null && headers != null)
            {
                int iHeaderIndex = headers.FindHeader("TID", "TID");

                // If we found the header, remove it.
                if (iHeaderIndex > -1)
                {
                    headers.RemoveAt(iHeaderIndex);
                    bRemoved = true;
                }
            }

            return(bRemoved);
        }
Ejemplo n.º 13
0
        public static int GetMessageSeqNumberFromIncomingHeaders()
        {
            int seqNum = -1;

            if (OperationContext.Current != null && OperationContext.Current.IncomingMessageHeaders != null)
            {
                MessageHeaders headers = OperationContext.Current.IncomingMessageHeaders;

                // get the TID object from the header
                ITID tid = TIDFactory.GetTIDFromMessage(headers);

                // if the TID was found, then set username to the TID's username
                if (tid != null)
                {
                    seqNum = (int)tid.Get(TIDField.MESSAGESEQNUMBER);
                }
            }

            return(seqNum);
        }
Ejemplo n.º 14
0
        /// <summary>
        /// This method can be called from within a service operation
        /// to retrieve the UserName associated with the TID of
        /// the message being processed by the service
        /// </summary>
        /// <returns>Returns the username of the TID.  If the
        /// OperationContext, the TID or the username cannot be found, it returns
        /// the empty string.</returns>
        public static string GetTIDUsername()
        {
            string strUsername = "";

            if (OperationContext.Current != null && OperationContext.Current.IncomingMessageHeaders != null)
            {
                MessageHeaders headers = OperationContext.Current.IncomingMessageHeaders;

                // get the TID object from the header
                ITID tid = TIDFactory.GetTIDFromMessage(headers);

                // if the TID was found, then set username to the TID's username
                if (tid != null)
                {
                    strUsername = (string)tid.Get(TIDField.USERNAME);
                }
            }

            return(strUsername);
        }
Ejemplo n.º 15
0
        /// <summary>
        ///  This method can be called from within a service operation
        /// to retrieve the ParamList associated with the TID of
        /// the message being processed by the service
        /// </summary>
        /// <returns>Returns the ParamList of the TID.  If the
        /// OperationContext, the TID or the ParamList cannot be found,
        /// it returns null.</returns>
        public static Dictionary <string, string> GetTIDParamList()
        {
            Dictionary <string, string> paramList = null;

            if (OperationContext.Current != null && OperationContext.Current.IncomingMessageHeaders != null)
            {
                MessageHeaders headers = OperationContext.Current.IncomingMessageHeaders;

                // get the TID object from the header
                ITID tid = TIDFactory.GetTIDFromMessage(headers);

                // if the TID was found, then set correlationID to the TID's correlationID
                if (tid != null)
                {
                    paramList = (Dictionary <string, string>)tid.Get(TIDField.PARAMLIST);
                }
            }

            return(paramList);
        }
Ejemplo n.º 16
0
        /// <summary>
        /// This method can be called from within a service operation
        /// to retrieve the CorrelationID associated with the TID of
        /// the message being processed by the service
        /// </summary>
        /// <returns>Returns the correlationID of the TID.  If the
        /// OperationContext, the TID or the correlationID cannot be found, it returns
        /// the empty string.</returns>
        public static string GetTIDCorrelationID()
        {
            string strCorrelationID = "";

            if (OperationContext.Current != null && OperationContext.Current.IncomingMessageHeaders != null)
            {
                MessageHeaders headers = OperationContext.Current.IncomingMessageHeaders;

                // get the TID object from the header
                ITID tid = TIDFactory.GetTIDFromMessage(headers);

                // if the TID was found, then set correlationID to the TID's correlationID
                if (tid != null)
                {
                    strCorrelationID = (string)tid.Get(TIDField.CORRELATIONID);
                }
            }

            return(strCorrelationID);
        }
Ejemplo n.º 17
0
        //
        //       _____________                 _____________
        //      |             | 1           2 |             |
        //      |             |-------------->|             |
        //      |   Client    |               | WCF Service |
        //      |             |<--------------|             |
        //      |             | 4           3 |             |
        //       -------------                 -------------
        //
        //   #1 = "BeforeSendRequest", which happens in the ASAClientMessageInspector
        //   #2 = "AfterReceiveRequest", which happens in the ASADispatchMessageInspector
        //   #3 = "BeforeSendReply", which happens in the ASADispatchMessageInspector
        //   #4 = "AfterReceiveReply", which happens in the ASAClientMessageInspector

        #region IDispatchMessageInspector interception methods

        /// <summary>
        /// o	AfterReceiveRequest():  This method will be used to audit TID information
        /// upon receiving a request from the client.  This method will:
        ///   -	Retrieve TID information from the header of the received message
        ///   - Update TID fields for situation of a request being received.
        ///     This will be done by the ASAMessageInspectionHelper.GetAfterReceivedRequestData() method.
        ///   - Call the TID class’ GetRecvTID() method
        ///   - send TID xml to the Logger for auditing.
        /// </summary>
        /// <param name="request"></param>
        /// <param name="channel"></param>
        /// <param name="instanceContext"></param>
        /// <returns></returns>
        public object AfterReceiveRequest(ref Message request, IClientChannel channel, InstanceContext instanceContext, ServiceDescription svcDescription)
        {
            try
            {
                //if the SOAP envelope of the request is 'None", then someone is just trying to get the mex endpoint.
                // we dont want to audit for that.
                if (request.Version.Envelope != System.ServiceModel.EnvelopeVersion.None)
                {
                    //load Parameters with ASA settings
                    Parameters.Instance.SectionName = "asa";

                    if (Parameters.Instance.EnableServiceRequestAudit == true)
                    {
                        OperationContext opCtx = OperationContext.Current;
                        ITID             tid   = TIDFactory.GetTIDFromMessage(request.Headers);
                        if (tid == null)
                        {
                            // the caller did not supply a TID.  Let's populate one with the info available to us.
                            tid = ASAMessageInspectionHelper.CreateNewTID(); //create a new TID object
                            MessageHeaders headers = request.Headers;
                            ASAMessageInspectionHelper.AddParamListFromMessageToTID(tid, headers);
                            ASAMessageInspectionHelper.AddMissingDefaultDataToTID(tid, headers, svcDescription);
                            ASAMessageInspectionHelper.AddTIDHeader(tid, ref headers);
                        }

                        // update the TID
                        if (tid != null)
                        {
                            //Add message payload to dictionary
                            Payload.AddMessagePayLoad(ASATIDHelper.GetTIDCorrelationID(), request.ToString());

                            //populate hashtable with fields that need to be updated after receiving request message.
                            Hashtable mapProps = ASAMessageInspectionHelper.GetAfterReceiveRequestData(tid, request.Headers, channel);

                            //call update the tid for sending.
                            tid = TIDFactory.GetRecvTID(request.Headers, mapProps);

                            //put this TID into the outgoing Message object.
                            MessageHeaders headers = opCtx.IncomingMessageHeaders;
                            ASAMessageInspectionHelper.AddTIDHeader(tid, ref headers);

                            // Check for config file entry "Enable_ServiceRequestAudit"
                            //audit the TID information in 'tid' using the new ASA Logger
                            string strTID = ASAMessageInspectionHelper.GetTIDString(headers);
                            Log.LogTID(strTID);
                        }
                        else
                        {
                            //Log error
                            Log.Error("TID object was not created properly by the caller of this service:" +
                                      channel.RemoteAddress.Uri.ToString(), this.strCorrelationIDForLogging.ToString());
                        }

                        if (Parameters.Instance.GetBoolValue("Enable_Authorization", false) == true)
                        {
                            AuthorizationManager.CheckAccess(TID.ASATIDHelper.GetTIDUsername(), request.Headers.Action);
                        }
                    }
                }
            }
            catch (ASAException exASA)
            {
                // log exception, then swallow it.
                Log.Error("Error in AfterReceiveRequest:" + exASA.Message + " Error_code:" + exASA.ExceptionError_id, exASA);
            }
            catch (ApplicationException exApp)
            {
                // log exception
                Log.Error("Error in AfterReceiveRequest", exApp);
                throw exApp;
            }
            catch (Exception ex)
            {
                // log exception, then swallow it.
                Log.Error("Error in AfterReceiveRequest", ex);
            }
            return(null);
        }
Ejemplo n.º 18
0
        /// <summary>
        /// o	BeforeSendRequest():  This method will be used to audit TID information
        /// before sending a request to the service.  This method will:
        ///   - Create a new TID object if this is the first call in a logical transaction.
        ///     (It is possible to tell this by the non-existence of an OperationContext in the proxy.)
        ///   - Retrieve TID information from the header of the received message if this is not
        ///     the first call in a logical transaction.   (It is possible to tell this by the
        ///     existence of an OperationContext in the proxy.)
        ///   - Update TID fields for situation of a request being sent.  This will be done by
        ///     the ASAMessageInspectionHelper.GetBeforeSendRequestData() method.
        ///   - Call the TID class’ GetSendTID() method
        ///   - send TID xml to the Logger for auditing.
        /// </summary>
        /// <param name="request"></param>
        /// <param name="channel"></param>
        /// <returns></returns>
        public object BeforeSendRequest(ref Message request, IClientChannel channel, ServiceEndpoint svcEndpoint)
        {
            try
            {
                //load Parameters with ASA settings
                Parameters.Instance.SectionName = "asa";

                if (Parameters.Instance.EnableClientRequestAudit == true)
                {
                    OperationContext opCtx = OperationContext.Current;
                    ITID             tid   = null;
                    if (opCtx != null) //this call is from inside a service
                    {
                        tid = TIDFactory.GetTIDFromMessage(opCtx.IncomingMessageHeaders);
                    }
                    if (tid == null)
                    {
                        //this call is from a .NET client or from the SAL
                        tid = ASAMessageInspectionHelper.CreateNewTID(); //create a new TID object
                    }
                    // update the TID
                    if (tid != null)
                    {
                        Hashtable mapProps = ASAMessageInspectionHelper.GetBeforeSendRequestData(tid, request.Headers, channel, svcEndpoint);

                        //call update the tid for sending.
                        tid = TIDFactory.GetSendTID(tid, mapProps);

                        //put the TID into the outgoing Message object.
                        MessageHeaders headers = request.Headers;
                        ASAMessageInspectionHelper.AddTIDHeader(tid, ref headers);

                        // Check for config file entry "Enable_ClientRequestAudit"
                        //audit the TID information in 'tid' using the new ASA Logger
                        string strTID = ASAMessageInspectionHelper.GetTIDString(headers);
                        Log.LogTID(strTID);
                    }
                    else
                    {
                        if (opCtx != null)
                        {
                            //Log error
                            Log.Error("TID object was not created properly by the caller of this service:" + request.Headers.Action,
                                      this.strCorrelationIDForLogging.ToString());//TODO: get URI of this service here.
                        }
                        else
                        {
                            //Log error
                            Log.Error("TID object was not created properly by this interception point on the client:" + Environment.MachineName,
                                      this.strCorrelationIDForLogging.ToString());
                        }
                    }
                }
            }
            catch (ASAException exASA)
            {
                // log exception, then swallow it.
                Log.Error("Error in BeforeSendRequest:" + exASA.Message + " Error_code:" + exASA.ExceptionError_id, exASA);
            }
            catch (Exception ex)
            {
                // log exception, then swallow it.
                Log.Error("Error in BeforeSendRequest", ex);
            }

            return(null);
        }
Ejemplo n.º 19
0
 public abstract bool SendTID(ITID tidIn, Hashtable mapPropsIn);
Ejemplo n.º 20
0
        /// <summary>
        /// o	AfterReceiveReply():  This method will be used to audit TID information
        /// upon receiving a reply from the service.  This method will:
        ///   - Retrieve TID information from the header of the received message
        ///   - Update TID fields for situation of a reply being received.  This will
        ///     be done by the ASAMessageInspectionHelper.GetAfterReceiveReplyData() method.
        ///   - Call the TID class’ GetRecvTID() method
        ///   - send TID xml to the Logger for auditing.
        /// </summary>
        /// <param name="reply"></param>
        /// <param name="correlationState"></param>
        public void AfterReceiveReply(ref Message reply, object correlationState)
        {
            try
            {
                //load Parameters with ASA settings
                Parameters.Instance.SectionName = "asa";

                if (Parameters.Instance.EnableClientResponseAudit == true)
                {
                    ITID tid = TIDFactory.GetTIDFromMessage(reply.Headers);

                    //added for QC 2364: populate some TID info even if service didnt return one,
                    // so long as we have an opCtx to pull some info from.
                    if (tid == null)
                    {
                        OperationContext opCtx = OperationContext.Current;
                        if (opCtx != null) //this call is from inside a service
                        {
                            MessageHeaders headers = reply.Headers;
                            tid = ASAMessageInspectionHelper.CreateNewTID();
                            Hashtable mapProps = ASAMessageInspectionHelper.GetReplyDataWhenNoTidWasFound(tid, headers);
                            tid = TIDFactory.GetCreateTID(mapProps);
                            ASAMessageInspectionHelper.AddTIDHeader(tid, ref headers);
                        }
                    }

                    // update the TID
                    if (tid != null)
                    {
                        MessageHeaders headers = reply.Headers;

                        //populate hashtable with fields needed when receiving the reply message.
                        Hashtable mapProps = ASAMessageInspectionHelper.GetAfterReceiveReplyData(tid, headers);

                        //call update the tid for sending.
                        tid = TIDFactory.GetRecvTID(headers, mapProps);
                        ASAMessageInspectionHelper.AddTIDHeader(tid, ref headers);

                        // Check for config file entry "Enable_ClientResponseAudit"
                        //audit the TID information in 'tid' using the new ASA Logger
                        string strTID = ASAMessageInspectionHelper.GetTIDString(headers);
                        Log.LogTID(strTID);

                        //Update MessageSequenceNumber within the OperationContext's tid for multihop scenario.
                        OperationContext opCtx = OperationContext.Current;
                        if (opCtx != null)
                        {
                            ITID tidFromOpContext = TIDFactory.GetTIDFromMessage(opCtx.IncomingMessageHeaders);
                            if (tidFromOpContext != null)
                            {
                                tidFromOpContext.Set(TIDField.MESSAGESEQNUMBER, ((int)tid.Get(TIDField.MESSAGESEQNUMBER)));
                                MessageHeaders opCtxHeaders = opCtx.IncomingMessageHeaders;
                                ASAMessageInspectionHelper.AddTIDHeader(tidFromOpContext, ref opCtxHeaders);
                            }
                        }
                    }
                    else
                    {
                        //Log error
                        Log.Error("TID object was not created properly by this interception point on the client or service:" + Environment.MachineName,
                                  this.strCorrelationIDForLogging.ToString()); //TODO: get URL of the service it's returning from?
                    }
                }
            }
            catch (ASAException exASA)
            {
                // log exception, then swallow it.
                Log.Error("Error in AfterReceiveReply:" + exASA.Message + " Error_code:" + exASA.ExceptionError_id, exASA);
            }
            catch (Exception ex)
            {
                // log exception, then swallow it.
                Log.Error("Error in AfterReceiveReply", ex);
            }
        }
Ejemplo n.º 21
0
        /// <summary>
        /// o	BeforeSendReply():  This method will be used to audit TID information before
        /// sending a reply message to the client.  This method will:
        ///    - Retrieve TID information from the header of the received message
        ///    - Update TID fields for situation of a reply being sent.
        ///      This will be done by the ASAMessageInspectionHelper.GetBeforeSendReplyData() method.
        ///    - Call the TID class’ GetSendTID() method
        ///    - send TID xml to the Logger for auditing.
        /// </summary>
        /// <param name="reply"></param>
        /// <param name="correlationState"></param>
        public void BeforeSendReply(ref Message reply, object correlationState, ServiceDescription svcDescription)
        {
            try
            {
                //if the SOAP envelope of the request is 'None", then someone is just trying to get the mex endpoint.
                // we dont want to audit for that.
                if (Parameters.Instance.EnableServiceResponseAudit == true)
                {
                    //load Parameters with ASA settings
                    Parameters.Instance.SectionName = "asa";

                    if (reply.Version.Envelope != System.ServiceModel.EnvelopeVersion.None)
                    {
                        OperationContext opCtx = OperationContext.Current;
                        ITID             tid   = TIDFactory.GetTIDFromMessage(opCtx.IncomingMessageHeaders);

                        // update the TID
                        if (tid != null)
                        {
                            //populate hashtable with fields needed before sending request message.
                            Hashtable mapProps = ASAMessageInspectionHelper.GetBeforeSendReplyData(tid, opCtx.IncomingMessageHeaders, svcDescription);
                            //call update the tid for sending.
                            tid = TIDFactory.GetSendTID(tid, mapProps);

                            //put the TID into the outgoing Message object.
                            MessageHeaders headers = reply.Headers;
                            ASAMessageInspectionHelper.AddTIDHeader(tid, ref headers);

                            // Check for config file entry "Enable_ServiceResponseAudit"
                            //audit the TID information in 'tid' using the new ASA Logger
                            string strTID = ASAMessageInspectionHelper.GetTIDString(headers);
                            Log.LogTID(strTID);

                            //remove message payload from dictionary
                            Payload.RemoveMessagePayLoad(ASATIDHelper.GetTIDCorrelationID());
                        }
                        else
                        {
                            //Log error
                            Log.Error("TID object was not created properly by this interception point:" + reply.Headers.To.ToString(),
                                      this.strCorrelationIDForLogging.ToString());//TODO: get URI of this service here.
                        }
                    }
                }

                // Fix for defect 391
                Parameters.Instance.SectionName = "asa";
                bool enableForcedGarbageCollection = Parameters.Instance.GetBoolValue("EnableForcedGarbageCollection", false);
                if (enableForcedGarbageCollection)
                {
                    GC.Collect(2, GCCollectionMode.Forced);
                }
            }
            catch (ASAException exASA)
            {
                // log exception, then swallow it.
                Log.Error("Error in BeforeSendReply:" + exASA.Message + " Error_code:" + exASA.ExceptionError_id, exASA);
            }
            catch (Exception ex)
            {
                // log exception, then swallow it.
                Log.Error("Error in BeforeSendReply", ex);
            }
        }
Ejemplo n.º 22
0
 /// <summary>
 /// Will retrieve the next MESSAGE SEQUENCE NUMBER based upon the TID passed in.
 /// </summary>
 /// <param name="dtOrigination"></param>
 /// <param name="tsTimeout"></param>
 /// <returns></returns>
 public static int GetMessageSequenceNumber(ITID tid)
 {
     return(((int)tid.Get(TIDField.MESSAGESEQNUMBER)) + 1);
 }