Exemple #1
0
        public object AfterReceiveRequest(ref Message request, System.ServiceModel.IClientChannel channel, System.ServiceModel.InstanceContext instanceContext)
        {
            var messageProperty = (HttpRequestMessageProperty)
                                  OperationContext.Current.IncomingMessageProperties[HttpRequestMessageProperty.Name];
            string cookie = messageProperty.Headers.Get("Set-Cookie");

            if (cookie == null) // Check for another Message Header - SL applications
            {
                cookie = messageProperty.Headers.Get("Cookie");
            }
            if (cookie == null)
            {
                cookie = string.Empty;
            }

            var authCookies      = new List <string>();
            var cookieValuePairs = cookie.Split(',', ';').Where(x => x.ToLower().Contains(FormsAuthentication.FormsCookieName.ToLower()));

            foreach (var pair in cookieValuePairs)
            {
                var splitted = pair.Split('=');
                var value    = splitted.Skip(1).First();
                authCookies.Add(value);
            }

            string encryptedTicket = string.Empty;

            // Set User Name from cookie
            if (authCookies.Count > 0)
            {
                encryptedTicket = authCookies.First().ToString();
            }

            FormsAuthenticationTicket ticket = null;
            string userName = string.Empty;
            string roles    = string.Empty;

            // Decrypt
            if (!string.IsNullOrEmpty(encryptedTicket))
            {
                ticket   = FormsAuthentication.Decrypt(encryptedTicket);
                userName = ticket.Name;
                roles    = ticket.UserData;
            }

            // Set Thread Principal to User Name
            if (!string.IsNullOrEmpty(userName))
            {
                CustomIdentity   customIdentity         = new CustomIdentity();
                GenericPrincipal threadCurrentPrincipal = new GenericPrincipal(customIdentity, roles.Split(',').Select(x => x.Trim()).ToArray());
                customIdentity.IsAuthenticated = true;
                customIdentity.Name            = userName;
                Thread.CurrentPrincipal        = threadCurrentPrincipal;
            }

            return(null);
        }
Exemple #2
0
        protected virtual void InspectRequestMessage(ref System.ServiceModel.Channels.Message request,
                                                     System.ServiceModel.IClientChannel channel,
                                                     System.ServiceModel.InstanceContext instanceContext)
        {
            ModuleProc PROC = new ModuleProc(this.DYN_MODULE_NAME, "LogReceiveRequest");

            try
            {
                if (this.LogRequestMessage)
                {
                    this.OnLogRequestMessage(PROC, request.ToString());
                }

                // process the message
                try
                {
                    OperationContext      context = null;
                    OperationContextScope scope   = null;

                    if (this.NeedOperationContext &&
                        OperationContext.Current != null)
                    {
                        context = OperationContext.Current;
                    }

                    try
                    {
                        if (this.NeedOperationContext &&
                            context == null)
                        {
                            scope   = new OperationContextScope(channel);
                            context = OperationContext.Current;
                        }

                        this.OnProcessRequestMessage(ref request, channel, instanceContext, context);
                    }
                    finally
                    {
                        if (scope != null)
                        {
                            scope.Dispose();
                        }
                    }
                }
                catch (Exception ex)
                {
                    Log.Exception(PROC, ex);
                }
            }
            catch (Exception ex)
            {
                Log.Exception(PROC, ex);
            }
        }
 /// <summary>
 /// Called after an inbound message has been received but
 /// before the message is dispatched to the intended operation.
 ///
 /// This method will also raise RaiseRequestReceived event.
 /// </summary>
 /// <param name="request">The request message.</param>
 /// <param name="channel">The incoming channel.</param>
 /// <param name="instanceContext">The current service instance.</param>
 /// <returns>
 /// The object used to correlate state.
 /// </returns>
 public object AfterReceiveRequest(
     ref System.ServiceModel.Channels.Message request,
     System.ServiceModel.IClientChannel channel,
     System.ServiceModel.InstanceContext instanceContext)
 {
     if (request != null)
     {
         Request = request.ToString();
     }
     OnRaiseRequestReceived(Request);
     return(null);
 }
Exemple #4
0
        public object BeforeSendRequest(ref Message request, System.ServiceModel.IClientChannel channel)
        {
            if (company != null && plant != null)
            {
                var vallCallSettings = new CallSettingsHeader()
                {
                    Company = company, Plant = plant
                };

                request.Headers.Add(vallCallSettings);
            }
            return(request);
        }
        public object AfterReceiveRequest(ref Message request, System.ServiceModel.IClientChannel channel, System.ServiceModel.InstanceContext instanceContext)
        {
            XmlConfigurator.Configure(new System.IO.FileInfo(Path.Combine(AssemblyDirectory, "log4netConfig.config")));
            MessageBuffer buffer      = request.CreateBufferedCopy(Int32.MaxValue);
            Message       copyRequest = buffer.CreateMessage();
            StringBuilder sb          = new StringBuilder();

            using (System.Xml.XmlWriter xw = System.Xml.XmlWriter.Create(sb))
            {
                copyRequest.WriteMessage(xw);
                xw.Flush();
                xw.Close();
            }
            log.Info(sb.ToString());
            request = buffer.CreateMessage();
            return(null);
        }
        /// <summary>
        /// 提交该单据对象相应的业务操作
        /// </summary>
        /// <param name="entity"></param>
        /// <param name="operateState"></param>
        /// <param name="remark"></param>
        /// <returns></returns>
        public virtual int BusinessFlowSubmit(object entity, MB.Util.Model.DocOperateType operateState, string remark)
        {
            object[] pars = new object[] { entity, operateState, remark };
            object   val  = null;

            using (TChannel serverRuleProxy = CreateServerRuleProxy()) {
                System.ServiceModel.IClientChannel channel = MB.Util.MyReflection.Instance.InvokePropertyForGet(serverRuleProxy, "InnerChannel") as System.ServiceModel.IClientChannel;
                using (System.ServiceModel.OperationContextScope scope = new System.ServiceModel.OperationContextScope(channel)) {
                    //增加消息表头信息
                    MB.WinBase.WcfClient.MessageHeaderHelper.AppendUserLoginInfo();
                    val = MB.WcfServiceLocator.WcfClientHelper.Instance.InvokeServerMethod(serverRuleProxy, "BusinessFlowSubmit", pars);
                }
                if (val == null || (int)val < 0)
                {
                    return(-1);
                }
            }
            return(1);
        }
Exemple #7
0
 public object AfterReceiveRequest(ref Message request, System.ServiceModel.IClientChannel channel, System.ServiceModel.InstanceContext instanceContext)
 {
     if (!request.IsFault && !request.IsEmpty)
     {
         // TODO: Implement auth key message behavior.
         //var commands = RdlCommandGroup.FromBytes(request.GetBody<byte[]>());
         //if (commands.Count > 0)
         //{
         //    if (!String.IsNullOrEmpty(commands.AuthKey))
         //    {
         //        AuthKey key = AuthKey.Get(commands.AuthKey);
         //        Server s = new Server();
         //        if (!s.World.Provider.ValidateAuthKey(key))
         //        {
         //            throw new FaultException(Resources.Resource.AuthorizationFailed);
         //        }
         //    }
         //}
     }
     return(null);
 }
        public object AfterReceiveRequest(ref Message request, System.ServiceModel.IClientChannel channel, System.ServiceModel.InstanceContext instanceContext)
        {
            string ModuleName = "ChannelProxyInspector";
            string MethodName = "AfterReceiveRequest";

            Utility _utility  = new Utility();
            string  messageId = _utility.GenerateNewGUID();

            NCR.EAI.Log.MessageLogger msgLogger = new NCR.EAI.Log.MessageLogger();

            MessageLog _messageLog = new MessageLog();

            _messageLog.CORRELATION_ID = messageId;
            _messageLog.SESSION_ID     = messageId;
            _messageLog.IN_OUT         = MessageLog.INOUT.IN_REQ.GetHashCode();

            msgLogger.addSoapRequesttoMsgLog(ref request, _messageLog, channel);
            //msgLogger.logSoapMessage();

            Logger.logDebug(ModuleName, MethodName, "Entered Method", Logger.LOGLEVEL.INFO);

            string requestString = request.ToString();

            Logger.logDebug(ModuleName, MethodName, "SessionID [" + messageId + "]", Logger.LOGLEVEL.INFO);
            if (Convert.ToBoolean(ConfigurationManager.AppSettings["LOG_MESSAGE"].ToString()))
            {
                string pattern  = @"\b(?:(4|5)([0-9]{1})([0-9]{4})([0-9]{6})([0-9]{4}))\b";
                string MASKCARD = "$1$2$3******$5";
                string DebugMsg = Regex.Replace(requestString, pattern, MASKCARD);

                Logger.logDebug(ModuleName, MethodName, "SessionID [" + messageId + "] Request Message: " + DebugMsg, Logger.LOGLEVEL.INFO);
            }
            msgLogger   = null;
            _messageLog = null;

            return(messageId);

            //throw new NotImplementedException();
        }
Exemple #9
0
        public object AfterReceiveRequest(ref Message request,
                                          System.ServiceModel.IClientChannel channel,
                                          System.ServiceModel.InstanceContext instanceContext)
        {
            var guidId = Guid.NewGuid().ToString();

            HttpContext.Current.Items["Requestid"] = guidId;
            try
            {
                var action = OperationContext.Current.IncomingMessageHeaders.Action;
                if (action == null)
                {
                    return(null);
                }
                action = action.Split('/').ToList().Last();
                var host      = HttpContext.Current.Request.Url.ToString();
                var sourceIp  = GetVisitorIpAddress();
                var starttime = DateTime.Now;
                HttpContext.Current.Items["StartTime"] = starttime;
                _logger.InitiliazeProcess(new LogData()
                {
                    AppName = ConfigurationManager.AppSettings["AppName"], Id = guidId, StartTime = starttime, Ip = sourceIp, Host = host, Method = action
                });
                _levelId = (int)_logger.InitiliazeItemOfProcess(new LogData()
                {
                    ReqXml = MessageToString(ref request), Id = guidId, Method = action, StartTime = DateTime.Now
                });
                HttpContext.Current.Items["levelid"] = _levelId;
                return(null);
            }
            catch (Exception ex)
            {
                var levelid = Convert.ToDecimal(HttpContext.Current.Items["levelid"]);

                return(null);
            }
        }
Exemple #10
0
        public object AfterReceiveRequest(ref System.ServiceModel.Channels.Message request, System.ServiceModel.IClientChannel channel, System.ServiceModel.InstanceContext instanceContext)
        {
            LogManager.GetLogger().Debug("AfterReceiveRequest");
            MessageBuffer buffer = request.CreateBufferedCopy(Int32.MaxValue);

            request = buffer.CreateMessage();
            //  System.ServiceModel.Channels.Message messageCopy = buffer.CreateMessage();

            // Read the custom context data from the headers
            ServiceHeader customData = CustomHeader.ReadHeader(request);

            // Add an extension to the current operation context so
            // that our custom context can be easily accessed anywhere.
            ServerContext customContext = new ServerContext();

            if (customData != null)
            {
                customContext.UserID           = customData.UserID;
                customContext.KerberosID       = customData.KerberosID;
                customContext.SiteminderToken  = customData.SiteminderToken;
                customContext.UserHeaderToken  = customData.UserToken;
                customContext.VerificationCode = customData.VerificationCode;
            }
            if (OperationContext.Current.IncomingMessageProperties.ContainsKey("CurrentContext"))
            {
                OperationContext.Current.IncomingMessageProperties.Remove("CurrentContext");
            }
            OperationContext.Current.IncomingMessageProperties.Add(
                "CurrentContext", customContext);
            //*****************
            object result;

            request.Properties.TryGetValue(TextOrMtomEncodingBindingElement.IsIncomingMessageMtomPropertyName, out result);
            return(result);
        }
Exemple #11
0
        /// <summary>
        /// Processa a requisição antes de enviar.
        /// </summary>
        /// <param name="request"></param>
        /// <param name="channel"></param>
        /// <returns></returns>
        public object BeforeSendRequest(ref System.ServiceModel.Channels.Message request, System.ServiceModel.IClientChannel channel)
        {
            object httpRequestMessageObject;

            if (request.Properties.TryGetValue(HttpRequestMessageProperty.Name, out httpRequestMessageObject))
            {
                var httpRequestMessage = httpRequestMessageObject as HttpRequestMessageProperty;
                httpRequestMessage.Headers[System.Net.HttpRequestHeader.ContentEncoding] = "gzip";
            }
            else
            {
                var httpRequestMessage = new HttpRequestMessageProperty();
                httpRequestMessage.Headers.Add(System.Net.HttpRequestHeader.ContentEncoding, "gzip");
                request.Properties.Add(HttpRequestMessageProperty.Name, httpRequestMessage);
            }
            return(null);
        }
            public object BeforeSendRequest(ref System.ServiceModel.Channels.Message request, System.ServiceModel.IClientChannel channel)
            {
                MessageHeader <string> header = new MessageHeader <string>(TenantContext.TenantName);

                request.Headers.Add(header.GetUntypedHeader(Constants.Headers.TenantNameHeaderName, Constants.Headers.TenantNameHeaderNamespace));
                header = new MessageHeader <string>(TenantContext.Username);
                request.Headers.Add(header.GetUntypedHeader(Constants.Headers.UsernnameHeaderName, Constants.Headers.UsernameHeaderNamespace));
                header = new MessageHeader <string>(TenantContext.Password);
                request.Headers.Add(header.GetUntypedHeader(Constants.Headers.PasswordHeaderName, Constants.Headers.PasswordHeaderNamespace));
                return(null);
            }
 public object BeforeSendRequest(ref System.ServiceModel.Channels.Message request, System.ServiceModel.IClientChannel channel)
 {
     //Console.WriteLine("客户端发送请求前的SOAP消息:\n{0}", request.ToString());
     //MessageHeader hdUserName = MessageHeader.CreateHeader("u", "f**k", "admin");
     //MessageHeader hdPassWord = MessageHeader.CreateHeader("p", "f**k", "123");
     //request.Headers.Add(hdUserName);
     //request.Headers.Add(hdPassWord);
     return(null);
 }
        /// <summary>
        /// BeforeSendRequest executes before a reply has been sent to the channel
        /// </summary>
        /// <param name="request">This parameter contains the request to the channel</param>
        /// <param name="channel">The channel to send to</param>
        /// <returns>A return value</returns>
        public object BeforeSendRequest(ref System.ServiceModel.Channels.Message request, System.ServiceModel.IClientChannel channel)
        {
            ExtendedPrincipal extendedPrincipal = Thread.CurrentPrincipal as ExtendedPrincipal;

            if (extendedPrincipal == null)
            {
                return(null);
            }

            return(null);
        }
Exemple #15
0
        public object AfterReceiveRequest(ref System.ServiceModel.Channels.Message request, System.ServiceModel.IClientChannel channel, InstanceContext instanceContext)
        {
            // If a token_key config entry exists in web.config, then this service requires authentication.
            // If the config does not exist, the service can be used without a security token.

            var    requestProperties = (HttpRequestMessageProperty)request.Properties[HttpRequestMessageProperty.Name];
            string endpoint          = request.Headers.To.ToString();

            try
            {
                if (!String.IsNullOrEmpty(endpoint) && endpoint.IndexOf("/") > -1)
                {
                    endpoint = endpoint.Substring(endpoint.LastIndexOf("/") + 1).ToLower();
                }
            } catch (Exception ex)
            {
                Logging.LogWriter.ERROR("endpoint parsing error" + ex.Message);
                Logging.LogWriter.ERROR(ex.InnerException.ToString());
            }


            if (!String.IsNullOrEmpty(token_key) && endpoint != "heartbeat")
            {
                //request.Headers.Action;


                IPHostEntry heserver = Dns.GetHostEntry(Dns.GetHostName());
                IPAddress   curAdd   = heserver.AddressList[0];
                host_info = curAdd.ToString();

                string authorization = requestProperties.Headers[HttpRequestHeader.Authorization];

                if (!String.IsNullOrEmpty(authorization))
                {
                    AuthenticationHeaderValue auth = new AuthenticationHeaderValue("Bearer", authorization.Substring("Bearer ".Length).Trim());
                    ClaimsPrincipal           principal;

                    try
                    {
                        principal = AuthenticateRequest(auth.Parameter);
                        Thread.CurrentPrincipal = principal;
                    }
                    catch (Exception e)
                    {
                        throw new FaultException <UnauthorizedAccessException>(
                                  new UnauthorizedAccessException("Error in request authentication: " + e.Message));
                    }

                    if (principal == null)
                    {
                        throw new FaultException <UnauthorizedAccessException>(new UnauthorizedAccessException());
                    }
                }
                else
                {
                    throw new FaultException <UnauthorizedAccessException>(new UnauthorizedAccessException("Request does not have authorization token"));
                }
            }
            else
            {
                // Service not configured to look for AuthTokens, allow traffic
            }

            return(instanceContext);
        }
Exemple #16
0
        public object BeforeSendRequest(ref System.ServiceModel.Channels.Message request, System.ServiceModel.IClientChannel channel)
        {
            MessageHeader <string> headerUser = new MessageHeader <string>();

            headerUser.Actor   = "anyone";
            headerUser.Content = UserName;
            MessageHeader unTypedHeaderUser = headerUser.GetUntypedHeader(hName, hNameSpace);

            request.Headers.Add(unTypedHeaderUser);

            MessageHeader <string> headerPwd = new MessageHeader <string>();

            headerPwd.Actor   = "anyone";
            headerPwd.Content = Password;
            MessageHeader unTypedHeaderPwd = headerPwd.GetUntypedHeader(hPwd, hNameSpace);

            request.Headers.Add(unTypedHeaderPwd);


            return(null);
        }
 public object BeforeSendRequest(ref System.ServiceModel.Channels.Message request, System.ServiceModel.IClientChannel channel)
 {
     return(request.Headers.Action);
 }
        public object AfterReceiveRequest(ref System.ServiceModel.Channels.Message request, System.ServiceModel.IClientChannel channel, System.ServiceModel.InstanceContext instanceContext)
        {
            Console.WriteLine(request);

            string username = GetHeaderValue("OperationUserName");

            string pwd = GetHeaderValue("OperationPwd");

            if (username == "robinzhang" && pwd == "111111")
            {
            }

            else
            {
                throw new Exception("操作中的用户名,密码不正确!");
            }

            return(null);
        }
        public object AfterReceiveRequest(ref System.ServiceModel.Channels.Message request, System.ServiceModel.IClientChannel channel, System.ServiceModel.InstanceContext instanceContext)
        {
            object prop;
            string myHeader;

            if (!OperationContext.Current.IncomingMessageProperties.TryGetValue(HttpRequestMessageProperty.Name, out prop))
            {
                myHeader = Guid.NewGuid().ToString();
            }
            else
            {
                HttpRequestMessageProperty reqProp = (HttpRequestMessageProperty)prop;
                myHeader = reqProp.Headers[X_ACTIVITY_ID_HTTP_HEADER];
            }

            Trace.CorrelationManager.ActivityId = Guid.Parse(myHeader);

            return(null);
        }
Exemple #20
0
        public object BeforeSendRequest(ref System.ServiceModel.Channels.Message request, System.ServiceModel.IClientChannel channel)
        {
            // We are going to send a request to Salesforce
            // Overview:
            // This behavior will do the following:
            // (1) Fetch Token from Salesforce, if required
            // (2) Add the token to the message
            // (3) Insert an Http Accept header so we get XML data in response, instead of JSON, which is default
            // Reference: http://www.salesforce.com/us/developer/docs/api_rest/index.htm
            //
            // (1) Authentication with Salesforce
            // (2) The token is added to the HTTP Authorization Header
            // (3) Add the Accept Header
            //

            HttpRequestMessageProperty httpRequest = null;

            if (request.Properties.ContainsKey(HttpRequestMessageProperty.Name))
            {
                httpRequest = request.Properties[HttpRequestMessageProperty.Name] as HttpRequestMessageProperty;
            }

            if (httpRequest == null)
            {
                // NOTE: Ideally, we shouldn’t get here for WebHttp
                httpRequest = new HttpRequestMessageProperty()
                {
                    Method             = "GET",
                    SuppressEntityBody = true
                };
                request.Properties.Add(HttpRequestMessageProperty.Name, httpRequest);
            }

            WebHeaderCollection headers = httpRequest.Headers;

            FetchOAuthToken();

            headers.Add(HttpRequestHeader.Authorization, "OAuth " + this.token_.access_token);
            headers.Add(HttpRequestHeader.Accept, "application/xml");

            return(null);
        }
Exemple #21
0
        /// <summary cref="IClientMessageInspector.BeforeSendRequest" />
        public object BeforeSendRequest(ref System.ServiceModel.Channels.Message request, System.ServiceModel.IClientChannel channel)
        {
            // extract request body from message object.
            IServiceMessage requestBody = (IServiceMessage)request.Properties[MessageProperties.RequestBody];

            // extract the request from the message body.
            IEncodeable encodeable = requestBody.GetRequest();

            byte[] encodedBody = null;

            if (!m_transportSupportsEncoding)
            {
                encodedBody = BinaryEncoder.EncodeMessage(encodeable, m_messageContext);
            }

            // create encoded message.
            Message encodedRequest = Message.CreateMessage(
                request.Version,
                Namespaces.OpcUaWsdl + "/InvokeService",
                new InvokeServiceBodyWriter(encodedBody, true));

            encodedRequest.Headers.To        = request.Headers.To;
            encodedRequest.Headers.MessageId = request.Headers.MessageId;
            encodedRequest.Headers.From      = request.Headers.From;

            if (encodedBody != null)
            {
                encodedRequest.Properties.Add(MessageProperties.EncodedBody, encodedBody);
            }

            encodedRequest.Properties.Add(MessageProperties.UnencodedBody, encodeable);

            // save information need to process reply.
            object correlationState = new object[] { request.Version, request.Headers.Action, requestBody };

            // replace the outgoing message.
            request = encodedRequest;

            return(correlationState);
        }
            public object BeforeSendRequest(ref System.ServiceModel.Channels.Message request, System.ServiceModel.IClientChannel channel)
            {
                UniqueId messageId = new UniqueId();

                // Set message ID
                soapMessages.SoapRequestMessageId = messageId.ToString();

                // Modify MessageId and From headers
                request.Headers.MessageId = messageId;

                // Removed as MCA have a problem with it ! Dont need it anyway !
                request.Headers.From = new EndpointAddress("http://www.w3.org/2005/08/addressing/anonymous");

                // To: Gets changed to endpointURI value anyway so it won't do this
                request.Headers.To = new Uri("http://www.w3.org/2005/08/addressing/anonymous");

                // Might want to check here for medicare body elements to see if signing is needed
                string outboundXml = string.Empty;

                request = SignBodyAndAddressingHeaders(request, ref outboundXml);

                soapMessages.SoapRequest = outboundXml;

                return(null);
            }
 public object AfterReceiveRequest(ref System.ServiceModel.Channels.Message request, System.ServiceModel.IClientChannel channel, System.ServiceModel.InstanceContext instanceContext)
 {
     //Console.WriteLine("服务器端:接收到的请求:\n{0}", request.ToString());
     //string un = request.Headers.GetHeader<string>("u", "f**k");
     //string ps = request.Headers.GetHeader<string>("p", "f**k");
     return(null);
 }
Exemple #24
0
        /// <summary>
        /// Processa a requisição antes de enviar.
        /// </summary>
        /// <param name="request">Mensagem da requisição.</param>
        /// <param name="channel">Canal do cliente.</param>
        /// <returns>Objecto correlacionado com o estado.</returns>
        public object BeforeSendRequest(ref System.ServiceModel.Channels.Message request, System.ServiceModel.IClientChannel channel)
        {
            object httpRequestMessageObject;

            if (request.Properties.TryGetValue(HttpRequestMessageProperty.Name, out httpRequestMessageObject))
            {
                var httpRequestMessage = httpRequestMessageObject as HttpRequestMessageProperty;
                if (string.IsNullOrWhiteSpace(httpRequestMessage.Headers[TokenHeaderName]))
                {
                    httpRequestMessage.Headers[TokenHeaderName]   = this.configuracao.Token;
                    httpRequestMessage.Headers[EmpresaHeaderName] = this.configuracao.Empresa;
                }
            }
            else
            {
                var httpRequestMessage = new HttpRequestMessageProperty();
                httpRequestMessage.Headers.Add(TokenHeaderName, this.configuracao.Token);
                httpRequestMessage.Headers.Add(EmpresaHeaderName, this.configuracao.Empresa);
                request.Properties.Add(HttpRequestMessageProperty.Name, httpRequestMessage);
            }

            request.Headers.Add(MessageHeader.CreateHeader(TokenHeaderName, Namespace, this.configuracao.Token));
            request.Headers.Add(MessageHeader.CreateHeader(EmpresaHeaderName, Namespace, this.configuracao.Empresa));

            return(null);
        }
 public object AfterReceiveRequest(ref System.ServiceModel.Channels.Message request, System.ServiceModel.IClientChannel channel, System.ServiceModel.InstanceContext instanceContext)
 {
     return(null);
 }
        public object BeforeSendRequest(ref System.ServiceModel.Channels.Message request, System.ServiceModel.IClientChannel channel)
        {
            string ModuleName = "NIMessageInspector";
            string MethodName = "BeforeSendingRequest";

            string remAddress = "";

            try
            {
                remAddress = channel.RemoteAddress.Uri.ToString();

                Logger.logDebug(ModuleName, MethodName, "Remote Address : " + remAddress, Logger.LOGLEVEL.INFO);
                if (remAddress.ToUpper().StartsWith("HTTPS"))
                {
                    ApplySSL();
                }
            }
            catch
            {
            }
            //request.Headers.To = "http://";
            //throw new NotImplementedException();
            //string luserName = "******";
            //string lPassword = "******";

            //this is done for not sending the action to MDM service as the service doesnt work
            //request.Headers.SetAction(null);

            string requestString = request.ToString();

            //request = TransformMessageBody(request, true);
            //requestString = "";


            if (Convert.ToBoolean(ConfigurationManager.AppSettings["LOG_NI_MESSAGE"].ToString()))
            {
                //   Logger.logDebug(ModuleName, MethodName, "Request Message: " + requestString, Logger.LOGLEVEL.INFO);
                string pattern  = @"\b(?:(4|5)([0-9]{1})([0-9]{4})([0-9]{6})([0-9]{4}))\b";
                string MASKCARD = "$1$2$3******$5";
                string DebugMsg = Regex.Replace(requestString, pattern, MASKCARD);

                Logger.logXMLMessage(ModuleName, MethodName, DebugMsg, Logger.LOGLEVEL.INFO, true);
            }
            //string sessionID = Guid.NewGuid().ToString();// channel.SessionId.ToString();

            Utilities.Utility _utility = new Utilities.Utility();

            string sessionID = _utility.GenerateNewGUID();// channel.SessionId.ToString();

            NCR.EAI.Log.MessageLogger msgLogger = new NCR.EAI.Log.MessageLogger();

            MessageLog _messageLog = new MessageLog();

            string messageID = "";

            try
            {
                OperationContext.Current.IncomingMessageProperties.Remove("SESSIONID");
            }
            catch (Exception ex)
            {
            }

            try
            {
                OperationContext.Current.IncomingMessageProperties.Add("SESSIONID", sessionID);
            }
            catch (Exception ex)
            {
            }

            //try
            //{
            //    messageID = OperationContext.Current.IncomingMessageProperties["MESSAGEID"].ToString();
            //}
            //catch (Exception ex)
            //{
            //    messageID = sessionID;
            //}
            messageID = sessionID;
            _messageLog.CORRELATION_ID = messageID;
            _messageLog.SESSION_ID     = sessionID;
            _messageLog.IN_OUT         = MessageLog.INOUT.OUT_REQ.GetHashCode();
            _messageLog.ADDRESS        = remAddress;

            msgLogger.addSoapRequesttoMsgLog(ref request, _messageLog, channel);


            return(sessionID);
        }
Exemple #27
0
        public object BeforeSendRequest(ref System.ServiceModel.Channels.Message request, System.ServiceModel.IClientChannel channel)
        {
            LogManager.GetLogger().Debug("BeforeSendRequest");
            MessageBuffer buffer = request.CreateBufferedCopy(Int32.MaxValue);

            request = buffer.CreateMessage();

            ServiceHeader customData = new ServiceHeader();

            customData.KerberosID       = ClientContextBucket.KerberosID;
            customData.SiteminderToken  = ClientContextBucket.SiteminderToken;
            customData.UserID           = ClientContextBucket.UserID;
            customData.UserToken        = ClientContextBucket.UserHeaderToken;
            customData.VerificationCode = ClientContextBucket.VerificationCode;
            CustomHeader header = new CustomHeader(customData);

            // Add the custom header to the request.
            request.Headers.Add(header);

            return(null);
        }
Exemple #28
0
            public object BeforeSendRequest(ref System.ServiceModel.Channels.Message request, System.ServiceModel.IClientChannel channel)
            {
                UniqueId messageId = new UniqueId();

                // Set message ID
                soapMessages.SoapRequestMessageId = messageId.ToString();

                // Modify MessageId and From headers
                request.Headers.MessageId = messageId;

                // Removed as MCA have a problem with it ! Dont need it anyway !
                request.Headers.From = new EndpointAddress("http://www.w3.org/2005/08/addressing/anonymous");

                // To: Gets changed to endpointURI value anyway so it won't do this
                request.Headers.To = new Uri("http://www.w3.org/2005/08/addressing/anonymous");

                // Might want to check here for medicare body elements to see if signing is needed
                string outboundXml = string.Empty;

                request = SignBodyAndAddressingHeaders(request, ref outboundXml);

                soapMessages.SoapRequest = outboundXml;

                //Below for debug, write to static file
                //DirectoryInfo DirectoryInfo = new DirectoryInfo(@"C:\temp\HIServiceSOAP");
                //if (!DirectoryInfo.Exists)
                //{
                //  DirectoryInfo.Create();
                //}
                //FileInfo FileInfo = new FileInfo($"{DirectoryInfo.FullName}\\{DateTime.Now.ToString("yyyyMMddTHHmmss")}_RequestSoap.xml");
                //File.WriteAllText(FileInfo.FullName, soapMessages.SoapRequest);

                return(null);
            }
Exemple #29
0
 public object BeforeSendRequest(ref System.ServiceModel.Channels.Message request, System.ServiceModel.IClientChannel channel)
 {
     sentMessages.Add(request.ToString());
     return(null);
 }
Exemple #30
0
        public object BeforeInvoke(System.ServiceModel.InstanceContext instanceContext, System.ServiceModel.IClientChannel channel, System.ServiceModel.Channels.Message message)
        {
            ApplicationContext context = message.Headers.GetHeader <ApplicationContext>(ApplicationContext.ContextHeaderLocalName, ApplicationContext.ContextHeaderNamespace);

            if (context == null)
            {
                return(null);
            }

            ApplicationContext.Current = context;
            return(ApplicationContext.Current);
        }