Exemplo n.º 1
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);
        }
Exemplo 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);
        }
Exemplo n.º 3
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);
        }
Exemplo n.º 4
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);
        }
Exemplo n.º 5
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);
        }
Exemplo n.º 6
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);
        }
Exemplo n.º 7
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);
        }
Exemplo n.º 8
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);
        }
Exemplo n.º 9
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);
 }
Exemplo n.º 10
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);
            }
        }