Esempio n. 1
0
        private static Message TraceOutMessage(System.ServiceModel.Channels.Message request, HttpRequestMessageProperty httpRequestMessageProperty)
        {
            var messageBuffer = request.CreateBufferedCopy(Int32.MaxValue);

            request = messageBuffer.CreateMessage();

            if (httpRequestMessageProperty != null)
            {
                var url = (request.Headers).To.OriginalString;
                Console.WriteLine("URI: " + url);
                Console.WriteLine("Method: " + httpRequestMessageProperty.Method);
            }

            StringBuilder sb = new StringBuilder();

            using (System.IO.TextWriter tw = new System.IO.StringWriter(sb))
            {
                using (System.Xml.XmlTextWriter xw = new System.Xml.XmlTextWriter(tw))
                {
                    xw.Formatting = System.Xml.Formatting.Indented;
                    request.WriteMessage(xw);
                }
            }

            Console.WriteLine(sb.ToString());
            Console.WriteLine();

            request = messageBuffer.CreateMessage();

            return(request);
        }
        public string SelectOperation(ref System.ServiceModel.Channels.Message message)
        {
            MessageBuffer buffer = message.CreateBufferedCopy(Int32.MaxValue);

            message = buffer.CreateMessage();

            var copy = buffer.CreateMessage();

            XmlDictionaryReader bodyReader  = copy.GetReaderAtBodyContents();
            XmlQualifiedName    lookupQName = new XmlQualifiedName(bodyReader.LocalName, bodyReader.NamespaceURI);

            if (dispatchDictionary.ContainsKey(lookupQName))
            {
                // Mark Soap Headers action etc as understood
                //int actionHeaderIdx = message.Headers.FindHeader("Action", "http://www.w3.org/2005/08/addressing");
                //int actionHeaderIdx2 = message.Headers.FindHeader("Action", "*");
                //message.Headers.UnderstoodHeaders.Add((MessageHeaderInfo)message.Headers[actionHeaderIdx]);
                //message.Headers.UnderstoodHeaders.Add((MessageHeaderInfo)message.Headers.FindHeader(Headers[0]);

                return(dispatchDictionary[lookupQName]);
            }
            else
            {
                return(null);
            }
        }
Esempio n. 3
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);
        }
Esempio n. 4
0
        public void BeforeSendReply(ref System.ServiceModel.Channels.Message reply, object correlationState)
        {
            if (!reply.IsEmpty && !reply.IsFault)
            {
                var buffer = reply.CreateBufferedCopy(short.MaxValue);
                var copy   = buffer.CreateMessage();
                reply = buffer.CreateMessage();

                string xmlMessage = copy.GetReaderAtBodyContents().ReadOuterXml();
                var    hashType   = WebOperationContext.Current.IncomingRequest.UriTemplateMatch.QueryParameters["hash"];

                if (hashType != null)
                {
                    byte[] hash = null;
                    if (hashType.Equals("MD5", StringComparison.OrdinalIgnoreCase))
                    {
                        MD5 md5 = MD5.Create();
                        hash = md5.ComputeHash(Encoding.UTF8.GetBytes(xmlMessage));
                    }
                    else if (hashType.Equals("SHA1", StringComparison.OrdinalIgnoreCase))
                    {
                        SHA1 sha1 = SHA1.Create();
                        hash = sha1.ComputeHash(Encoding.UTF8.GetBytes(xmlMessage));
                    }

                    if (hash != null)
                    {
                        WebOperationContext.Current.OutgoingResponse.Headers.Add("Hash", Convert.ToBase64String(hash));
                    }
                }
            }
        }
Esempio n. 5
0
        public void BeforeSendReply(ref System.ServiceModel.Channels.Message reply, object correlationState)
        {
            MessageBuffer buffer = reply.CreateBufferedCopy(Int32.MaxValue);

            reply = buffer.CreateMessage();
            Console.WriteLine("Message Sending:\n{0}", buffer.CreateMessage().ToString());
        }
Esempio n. 6
0
        //Server Side
        public void BeforeSendReply(ref System.ServiceModel.Channels.Message reply, object correlationState)
        {
            X509Certificate2 myCert = CryptoHelper.FindCertificate(StoreLocation.LocalMachine, StoreName.My, X509FindType.FindBySubjectDistinguishedName, "CN=klServer");

            byte[] myHash = myCert.GetCertHash();

            byte[] mySignedHash         = CryptoHelper.Sign(myHash, myCert);
            byte[] mySignedDetachedHash = CryptoHelper.SignDetached(myHash, myCert);

            byte[] myEncryptedHash         = CryptoHelper.Encrypt(mySignedHash, myCert);
            byte[] myEncryptedDetachedHash = CryptoHelper.Encrypt(mySignedDetachedHash, myCert);

            byte[] myDecodedHash = CryptoHelper.VerifyAndRemoveSignature(mySignedHash);

            bool myOK = CryptoHelper.VerifyDetached(mySignedHash, mySignedDetachedHash);

            char[] keyChars = new char[mySignedHash.Length];

            for (int i = 0; i < mySignedHash.Length; i++)
            {
                keyChars[i] = (char)mySignedHash[i];
            }

            reply.Headers.Add((new CustomSecurityHeader(new string(keyChars))));

            MessageBuffer buffer = reply.CreateBufferedCopy(Int32.MaxValue);

            reply = buffer.CreateMessage();
            Console.WriteLine("Service Sending:\n{0}", buffer.CreateMessage().ToString());
        }
Esempio n. 7
0
        public object AfterReceiveRequest(ref System.ServiceModel.Channels.Message request, System.ServiceModel.IClientChannel channel, System.ServiceModel.InstanceContext instanceContext)
        {
            bool isVersionExist = false;

            for (int i = 0; i < request.Headers.Count; i++)
            {
                var headerInfo = request.Headers[i];
                if (headerInfo.Name == "Version" && headerInfo.Namespace == "http://WcfPoc.wcfRouting.int/Increment1")
                {
                    isVersionExist = true;
                    break;
                }
            }

            //if (!isVersionExist)
            //{
            //    throw new Exception("SOAP Message don't have VERSION header!");
            //}

            MessageBuffer buffer = request.CreateBufferedCopy(Int32.MaxValue);

            request = buffer.CreateMessage();
            Console.WriteLine("Message Received:\n{0}", buffer.CreateMessage().ToString());

            return(null);
        }
Esempio n. 8
0
        public object AfterReceiveRequest(ref System.ServiceModel.Channels.Message request, System.ServiceModel.IClientChannel channel, System.ServiceModel.InstanceContext instanceContext)
        {
            if (!_traceMessages && !_traceMessageHeaders)
            {
                return(null);
            }
            StringBuilder logMessage = new StringBuilder();
            MessageBuffer buffer     = request.CreateBufferedCopy(Int32.MaxValue);

            request = buffer.CreateMessage();
            Message originalMessage = buffer.CreateMessage();

            logMessage.AppendLine("Received:");
            logMessage.AppendLine();
            if (_traceMessageHeaders)
            {
                foreach (MessageHeader header in originalMessage.Headers)
                {
                    string headerString = header.ToString();
                    logMessage.AppendLine(headerString);
                }
            }
            if (_traceMessages)
            {
                logMessage.AppendLine();
                string soapMessage = originalMessage.ToString();
                logMessage.AppendLine(soapMessage);
            }
            string logMessageString = logMessage.ToString();

            GOCWindows.Instance.Logger.LogMessage(new LogMessage(logMessageString, LogMessageType.Information, LoggingLevel.Maximum));
            return(null);
        }
Esempio n. 9
0
            public void AfterReceiveReply(ref System.ServiceModel.Channels.Message reply, object correlationState)
            {
                MessageBuffer msgBuffer = reply.CreateBufferedCopy(int.MaxValue);

                MemoryStream ms = new MemoryStream();

                msgBuffer.WriteMessage(ms);

                ms.Position = 0;

                StreamReader sr     = new StreamReader(ms);
                string       output = sr.ReadToEnd();

                sr.Close();

                soapMessages.SoapResponse          = output;
                soapMessages.SoapResponseMessageId = GetMessageId(output);

                reply = msgBuffer.CreateMessage();

                msgBuffer.Close();

                //Below for debug, write Soap 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")}_ResponseSoap.xml");
                //File.WriteAllText(FileInfo.FullName, soapMessages.SoapRequest);

                // Comment this out as if error back from ESB - it doesn't get passed Validation
                // bool isValid = VerifyXML(soapMessages.SoapResponse);
                // soapMessages.IsSoapResponseSignatureValid = VerifyXML(soapMessages.SoapResponse);
            }
            public void AfterReceiveReply(ref System.ServiceModel.Channels.Message reply, object correlationState)
            {
                MessageBuffer msgBuffer = reply.CreateBufferedCopy(int.MaxValue);

                MemoryStream ms = new MemoryStream();

                msgBuffer.WriteMessage(ms);

                ms.Position = 0;

                StreamReader sr     = new StreamReader(ms);
                string       output = sr.ReadToEnd();

                sr.Close();

                soapMessages.SoapResponse          = output;
                soapMessages.SoapResponseMessageId = GetMessageId(output);

                reply = msgBuffer.CreateMessage();

                msgBuffer.Close();

                // Comment this out as if error back from ESB - it doesn't get passed Validation
                // bool isValid = VerifyXML(soapMessages.SoapResponse);
                // soapMessages.IsSoapResponseSignatureValid = VerifyXML(soapMessages.SoapResponse);
            }
Esempio n. 11
0
        public void BeforeSendReply(ref System.ServiceModel.Channels.Message reply, object correlationState)
        {
            if (!_traceMessages && !_traceMessageHeaders)
            {
                return;
            }
            StringBuilder logMessage = new StringBuilder();
            MessageBuffer buffer     = reply.CreateBufferedCopy(Int32.MaxValue);

            reply = buffer.CreateMessage();
            Message originalMessage = buffer.CreateMessage();

            logMessage.AppendLine("Sending:");
            logMessage.AppendLine();
            if (_traceMessageHeaders)
            {
                foreach (MessageHeader header in originalMessage.Headers)
                {
                    string headerString = header.ToString();
                    logMessage.AppendLine(headerString);
                }
            }
            if (_traceMessages)
            {
                logMessage.AppendLine();
                string soapMessage = originalMessage.ToString();
                logMessage.AppendLine(soapMessage);
            }
            string logMessageString = logMessage.ToString();

            GOCWindows.Instance.Logger.LogMessage(new LogMessage(logMessageString, LogMessageType.Information, LoggingLevel.Maximum));
        }
            public object AfterReceiveRequest(ref System.ServiceModel.Channels.Message request, IClientChannel channel, InstanceContext instanceContext)
            {
                // Workaround for Service Bus scenario for PUT&POST
                MessageBuffer     buffer         = request.CreateBufferedCopy(int.MaxValue);
                Message           copy           = buffer.CreateMessage();
                MemoryStream      ms             = new MemoryStream();
                Encoding          encoding       = Encoding.UTF8;
                XmlWriterSettings writerSettings = new XmlWriterSettings {
                    Encoding = encoding
                };
                XmlDictionaryWriter writer = XmlDictionaryWriter.CreateDictionaryWriter(XmlWriter.Create(ms));

                copy.WriteBodyContents(writer);
                writer.Flush();
                string messageBodyString = encoding.GetString(ms.ToArray());

                messageBodyString = @"<?xml version=""1.0"" encoding=""utf-8""?><Binary>" +
                                    Convert.ToBase64String(Encoding.UTF8.GetBytes(messageBodyString)) + "</Binary>";
                ms = new MemoryStream(encoding.GetBytes(messageBodyString));
                XmlReader bodyReader      = XmlReader.Create(ms);
                Message   originalMessage = request;

                request = Message.CreateMessage(originalMessage.Version, null, bodyReader);
                request.Headers.CopyHeadersFrom(originalMessage);

                if (!request.Properties.ContainsKey(WebBodyFormatMessageProperty.Name))
                {
                    request.Properties.Add(WebBodyFormatMessageProperty.Name, new WebBodyFormatMessageProperty(WebContentFormat.Raw));
                }

                return(null);
            }
Esempio n. 13
0
        public void AfterReceiveReply(ref System.ServiceModel.Channels.Message reply, object correlationState)
        {
            if (reply.IsFault)
            {
                string       action             = reply.Headers.Action;
                var          type               = reply.Version.Addressing.GetType();
                PropertyInfo prop               = type.GetProperty("DefaultFaultAction", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
                var          defaultActionValue = (string)prop.GetValue(reply.Version.Addressing, null);

                //If we get Action element with default value its value will be lost during conversion to FaultException object
                //So we won't distinct between typed exceptions with default Action's value and typed exceptions without Action element
                //Solution: instead of default value set Action element to value "<DefaultAction>" and handle it as a special case
                if (null != reply.Headers.Action && reply.Headers.Action == defaultActionValue)
                {
                    action = "<DefaultAction>";
                }

                //var newReply = Message.CreateMessage(reply.Version, action, reply.GetReaderAtBodyContents());
                //var copy = reply.CreateBufferedCopy(int.MaxValue);
                //var newReply = Message.CreateMessage(reply.Version, action, copy.CreateMessage().GetReaderAtBodyContents());
                var newReply = reply.CreateBufferedCopy(int.MaxValue).CreateMessage();
                if (null != newReply.Headers)
                {
                    newReply.Headers.Action = action;
                }

                reply = newReply;
            }
        }
Esempio n. 14
0
        public void AfterReceiveReply(ref System.ServiceModel.Channels.Message reply, object correlationState)
        {
            lock (_syncObject)
            {
                if (MessageSink != null)
                {
                    // so bizarre...but if you don't, you'll ruin comms between the service and client
                    MessageBuffer buffer = reply.CreateBufferedCopy(Int32.MaxValue);
                    reply = buffer.CreateMessage();
                    // so bizarre...but if you don't, you'll ruin comms between the service and client

                    Message       msg = buffer.CreateMessage();
                    StringBuilder sb  = new StringBuilder();
                    XmlWriter     xw  = XmlWriter.Create(sb);
                    msg.WriteBody(xw);
                    xw.Close();

                    MessageSink.WriteMessage(String.Format("Received ({0}):", DateTime.Now.ToUniversalTime().ToString()));
                    MessageSink.WriteMessage(msg.ToString());
                    MessageSink.WriteMessage("Body:");
                    MessageSink.WriteMessage(sb.ToString());
                    buffer.Close();
                }
            }
        }
Esempio n. 15
0
        public void BeforeSendReply(ref System.ServiceModel.Channels.Message reply, object correlationState)
        {
            MessageBuffer requstBuffer = reply.CreateBufferedCopy(int.MaxValue);
            Message       msg          = requstBuffer.CreateMessage();

            reply = requstBuffer.CreateMessage();
        }
Esempio n. 16
0
        public void BeforeSendReply(ref System.ServiceModel.Channels.Message reply, object correlationState)
        {
            var log = (Log)correlationState;

            reply = CopyAndLogMessage(log, reply.CreateBufferedCopy(int.MaxValue), "BeforeSendReply");
            log.Flush();
        }
 public object AfterReceiveRequest(ref System.ServiceModel.Channels.Message request, IClientChannel channel, InstanceContext instanceContext)
 {
     // set the required state for logging, which is a shared IDictionary stored in OperationContext.Current (See WcfInteractionState.cs)
     _state[Constants.ServiceRequestUriKey]             = request.Headers.To;
     _state[Constants.InternalCorrelationIdentifierKey] = Guid.NewGuid();
     request = CopyLogMessage(request.CreateBufferedCopy(int.MaxValue));
     return(null);
 }
Esempio n. 18
0
        public void AfterReceiveReply(ref System.ServiceModel.Channels.Message reply, object correlationState)
        {
            MessageBuffer buffer = reply.CreateBufferedCopy(int.MaxValue);

            _receivedMessage = buffer.CreateMessage();

            reply = buffer.CreateMessage();
        }
Esempio n. 19
0
 public static ServiceModelChannels.Message CopyMessageFromBuffer(ref ServiceModelChannels.Message message)
 {
     using (ServiceModelChannels.MessageBuffer msgbuf = message.CreateBufferedCopy(int.MaxValue))
     {
         ServiceModelChannels.Message returnMessage = msgbuf.CreateMessage();
         message = msgbuf.CreateMessage();
         return(returnMessage);
     }
 }
Esempio n. 20
0
        public object AfterReceiveRequest(ref System.ServiceModel.Channels.Message request, IClientChannel channel, InstanceContext instanceContext)
        {
            var buffer = request.CreateBufferedCopy(int.MaxValue);
            var path   = Path.Combine(Path.GetTempPath(), "wcf-rest-log.txt");
            var log    = new Log(path, request.Headers.To);

            request = CopyAndLogMessage(log, buffer, "AfterReceiveRequest");
            return(log);
        }
        /// <summary>
        /// Enables inspection or modification of a message before a request message is sent to a service.
        /// </summary>
        /// <param name="request">The message to be sent to the service.</param>
        /// <param name="channel">The  client object channel.</param>
        /// <returns>
        /// The object that is returned as the <paramref name="correlationState " />argument of the <see cref="M:System.ServiceModel.Dispatcher.IClientMessageInspector.AfterReceiveReply(System.ServiceModel.Channels.Message@,System.Object)" /> method. This is null if no correlation state is used.The best practice is to make this a <see cref="T:System.Guid" /> to ensure that no two <paramref name="correlationState" /> objects are the same.
        /// </returns>
        protected object BeforeSendRequest(ref System.ServiceModel.Channels.Message request, System.ServiceModel.IClientChannel channel)
        {
            // Prepare the request message copy to be modified
            MessageBuffer buffer = request.CreateBufferedCopy(Int32.MaxValue);

            request = buffer.CreateMessage();

            request.Headers.Add(new AuthenticationMessageHeader(this.m_UserName, this.m_Password));
            return(null);
        }
Esempio n. 22
0
 /// <summary>
 /// Processa a respota recebida.
 /// </summary>
 /// <param name="reply"></param>
 /// <param name="correlationState"></param>
 public void AfterReceiveReply(ref System.ServiceModel.Channels.Message reply, object correlationState)
 {
     if (reply.IsFault)
     {
         var buffer = reply.CreateBufferedCopy(Int32.MaxValue);
         var copy   = buffer.CreateMessage();
         reply = buffer.CreateMessage();
         var messageFault = MessageFault.CreateFault(copy, 0x10000);
         throw FaultException.CreateFault(messageFault);
     }
 }
Esempio n. 23
0
        public object BeforeSendRequest(ref System.ServiceModel.Channels.Message request, IClientChannel channel)
        {
            MessageBuffer buffer = request.CreateBufferedCopy(Int32.MaxValue);

            request = buffer.CreateMessage();
            List <object> results = new List <object> {
                string.Format("Sending:\n{0}", buffer.CreateMessage().ToString())
            };

            _logger.WriteLogEntry(results, "BeforeSendRequest", LogLevelType.Trace);
            return(null);
        }
        public object AfterReceiveRequest(ref System.ServiceModel.Channels.Message request, System.ServiceModel.IClientChannel channel, System.ServiceModel.InstanceContext instanceContext)
        {
            using (MessageBuffer buffer = request.CreateBufferedCopy(Int32.MaxValue))
            {
                request = buffer.CreateMessage();
                var action = request.Headers.Action.Split('/');

                Console.WriteLine("Received request for :\n{0}", action.Last());

                //   Console.ReadKey();
                return(request);
            }
        }
Esempio n. 25
0
        /// <summary>
        /// This method removes the empty tags from the soap request before sending the request to the server.
        /// </summary>
        /// <param name="request"></param>
        /// <param name="channel"></param>
        /// <returns></returns>
        public object BeforeSendRequest(ref System.ServiceModel.Channels.Message request, System.ServiceModel.IClientChannel channel)
        {
            MemoryStream memoryStream = new MemoryStream();
            XmlWriter    xmlWriter    = XmlWriter.Create(memoryStream);

            request.WriteMessage(xmlWriter);
            xmlWriter.Flush();
            memoryStream.Position = 0;
            XmlDocument xmlDocument = new XmlDocument();

            xmlDocument.Load(memoryStream);

            XmlNamespaceManager xmlNamespaceManager = new XmlNamespaceManager(xmlDocument.NameTable);

            xmlNamespaceManager.AddNamespace("env", "http://schemas.xmlsoap.org/soap/envelope/");
            XmlNode header = xmlDocument.SelectSingleNode("//env:Header", xmlNamespaceManager);

            if (header != null)
            {
                header.ParentNode.RemoveChild(header);
            }

            XmlNodeList nodes = xmlDocument.SelectNodes("//node()");

            foreach (XmlNode node in nodes)
            {
                if (node.NodeType == XmlNodeType.Element && node.ChildNodes.Count == 0 && node.InnerXml == "")
                {
                    node.ParentNode.RemoveChild(node);
                }
            }
            memoryStream = new MemoryStream();
            xmlDocument.Save(memoryStream);
            memoryStream.Position = 0;
            XmlReader xmlReader = XmlReader.Create(memoryStream);

            System.ServiceModel.Channels.Message newMessage = System.ServiceModel.Channels.Message.CreateMessage(xmlReader, int.MaxValue, request.Version);
            newMessage.Headers.CopyHeadersFrom(request.Headers);
            newMessage.Properties.CopyProperties(request.Properties);

            //Logging processed request
            MessageBuffer buffer = newMessage.CreateBufferedCopy(Int32.MaxValue);

            newMessage = buffer.CreateMessage();
            LogRequestResponse(buffer, "Opportunity Service Request");

            request = newMessage;
            return(request);
        }
Esempio n. 26
0
        public object BeforeSendRequest(ref System.ServiceModel.Channels.Message request, System.ServiceModel.IClientChannel channel)
        {
            request = TransformMessage(request);

            MessageBuffer buffer = request.CreateBufferedCopy(int.MaxValue);
            Message       copy   = buffer.CreateMessage();

            var logger = Log4NetLogger.Configure();

            logger.Information(GetDocumentFromMessage(buffer.CreateMessage()).OuterXml);

            request = buffer.CreateMessage();

            return(null);
        }
Esempio n. 27
0
        public void AfterReceiveReply(ref System.ServiceModel.Channels.Message reply, object correlationState)
        {
            if (reply is null)
            {
                throw new ArgumentNullException(nameof(reply));
            }

            using (var buffer = reply.CreateBufferedCopy(int.MaxValue))
            {
                var document = GetDocument(buffer.CreateMessage());
                Logger.LogTrace(document.OuterXml);

                reply = buffer.CreateMessage();
            }
        }
 /// <summary>
 /// Processa a respota recebida.
 /// </summary>
 /// <param name="reply"></param>
 /// <param name="correlationState"></param>
 public void AfterReceiveReply(ref System.ServiceModel.Channels.Message reply, object correlationState)
 {
     if (reply.IsFault)
     {
         var buffer = reply.CreateBufferedCopy(Int32.MaxValue);
         var copy   = buffer.CreateMessage();
         reply = buffer.CreateMessage();
         var messageFault = MessageFault.CreateFault(copy, 0x10000);
         if ((messageFault.Code.Name == InvalidTokenFaultReasonCode || messageFault.Code.Name == EmptyTokenFaultReasonCode) && messageFault.Code.Namespace == Namespace)
         {
             throw new InvalidSecurityTokenException(messageFault.Reason.ToString(), FaultException.CreateFault(messageFault));
         }
         throw FaultException.CreateFault(messageFault);
     }
 }
Esempio n. 29
0
        public object BeforeSendRequest(ref System.ServiceModel.Channels.Message request, IClientChannel channel)
        {
            if (request is null)
            {
                throw new ArgumentNullException(nameof(request));
            }

            using (var buffer = request.CreateBufferedCopy(int.MaxValue))
            {
                var document = GetDocument(buffer.CreateMessage());
                Logger.LogTrace(document.OuterXml);

                request = buffer.CreateMessage();
                return(null);
            }
        }
Esempio n. 30
0
        public object AfterReceiveRequest(ref System.ServiceModel.Channels.Message request, System.ServiceModel.IClientChannel channel, System.ServiceModel.InstanceContext instanceContext)
        {
            //create a copy of the message since a message can be read only once
            MessageBuffer buffer = request.CreateBufferedCopy(Int32.MaxValue);

            request = buffer.CreateMessage();
            Message dupeRequest = buffer.CreateMessage();

            //log the action
            Helper.Log(dupeRequest.Headers.Action);

            buffer.Close();

            Helper.Log("IDispatchMessageInspector.AfterReceiveRequest() called from " + Helper.GetClientIP());
            return(null);
        }