当前位置: 首页>>代码示例>>C#>>正文


C# Message.CreateBufferedCopy方法代码示例

本文整理汇总了C#中Message.CreateBufferedCopy方法的典型用法代码示例。如果您正苦于以下问题:C# Message.CreateBufferedCopy方法的具体用法?C# Message.CreateBufferedCopy怎么用?C# Message.CreateBufferedCopy使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Message的用法示例。


在下文中一共展示了Message.CreateBufferedCopy方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: BeforeSendReply

        public void BeforeSendReply(ref Message reply, object correlationState)
        {
            MessageBuffer messageBuffer = reply.CreateBufferedCopy(Int32.MaxValue);

            // Create string builders
            StringBuilder source = GetMessageBufferAsStringBuilder(messageBuffer);

            // In case of an error, do not modify the message
            if (source.ToString().StartsWith("<s:Fault"))
            {
                reply = messageBuffer.CreateMessage();
                return;
            }

            StringBuilder target = new StringBuilder();

            // Read source xml
            StringReader sr = new StringReader(source.ToString());
            XmlTextReader reader = new XmlTextReader(sr);

            // Write target xml
            StringWriter sw = new StringWriter(target);
            XmlManglingWriter writer = new XmlManglingWriter(sw);
            writer.WriteNode(reader, true);

            reader.Close();
            writer.Flush();
            writer.Close();

            // Set target message
            reply = GetStringBuilderAsNewMessage(reply, target);

            // Log message
            //MessageLogger.LogReply(ref reply, log);
        }
开发者ID:Klaudit,项目名称:inbox2_desktop,代码行数:35,代码来源:CloudMessageInspector.cs

示例2: SelectOperation

        public string SelectOperation(ref Message message)
        {
            // TODO: check message format (raw)

            // Ignore non-POST requests
            if (!EnsurePostRequest(message))
                return null;

            if (message.Properties.ContainsKey("HttpOperationName"))
                return (string)message.Properties["HttpOperationName"];

            Message messageCopy;
            using (MessageBuffer buffer = message.CreateBufferedCopy(Int32.MaxValue)) {                
                message = buffer.CreateMessage();
                messageCopy = buffer.CreateMessage();                
            }

            string operation = SelectOperationInternal(messageCopy);
            if (operation == null)
                throw new InvalidOperationException("Invalid message format.");

            message.Properties["HttpOperationName"] = operation;

            return operation;
        }
开发者ID:yonglehou,项目名称:JsonRpc.ServiceModel,代码行数:25,代码来源:JsonRpcOperationSelector.cs

示例3: AfterReceiveReply

        //Client Side
        public void AfterReceiveReply(ref Message reply, object correlationState)
        {
            MessageBuffer buffer = reply.CreateBufferedCopy(Int32.MaxValue);
            reply = buffer.CreateMessage();
            Console.WriteLine("Client Received:\n{0}", buffer.CreateMessage().ToString());

            X509Certificate2 myCert = CryptoHelper.FindCertificate(StoreLocation.LocalMachine, StoreName.My, X509FindType.FindBySubjectDistinguishedName, "CN=klServer");
            byte[] myHash = myCert.GetCertHash();

            Int32 headerPosition = reply.Headers.FindHeader(CustomHeaderNames.CustomHeaderName, CustomHeaderNames.CustomHeaderNamespace);

            XmlDictionaryReader reader = reply.Headers.GetReaderAtHeader(headerPosition);

            CustomSecurityHeader header = CustomSecurityHeader.ReadHeader(reader);

            string mySignedHashString = header.Key;

            char[] mysignedHashCharArray = mySignedHashString.ToArray();

            byte[] mySignedHash = new byte[mySignedHashString.Length];
            for (int i = 0; i < mySignedHashString.Length; i++)
                mySignedHash[i] =(byte) mysignedHashCharArray[i];

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

            for(int i=0;i<myHash.Length;i++)
            {
                if (myDecodedHash[i] != myHash[i])
                {
                    throw new Exception("Access Denied");
                }
            }
        }
开发者ID:virajs,项目名称:klWCFSecurity,代码行数:34,代码来源:Service1.cs

示例4: AfterReceiveRequest

        public object AfterReceiveRequest(
            ref Message request, IClientChannel channel, InstanceContext instanceContext)
        {
            MessageBuffer buffer = request.CreateBufferedCopy(int.MaxValue);

            try
            {
                XmlReaderSettings settings = new XmlReaderSettings();
                settings.Schemas.Add(schemas);
                settings.ValidationType = ValidationType.Schema;
                
                Message msgToValidate = buffer.CreateMessage();
                XmlReader reader = XmlReader.Create(
                    msgToValidate.GetReaderAtBodyContents().ReadSubtree(), settings);

                while (reader.Read()) ; // do nothing, just validate

                request = buffer.CreateMessage();
            }
            catch (Exception e)
            {
                throw new FaultException(e.Message);
            }
            return null;
        }
开发者ID:ssickles,项目名称:archive,代码行数:25,代码来源:XsdValidationInspector.cs

示例5: CompressMessage

 public Message CompressMessage(Message sourceMessage)
 {
     byte[] buffer;
     MessageBuffer messageBuffer = sourceMessage.CreateBufferedCopy(int.MaxValue);
     sourceMessage.Close();
     sourceMessage = messageBuffer.CreateMessage();
     using (XmlDictionaryReader reader1 = sourceMessage.GetReaderAtBodyContents())
     {
         buffer = Encoding.UTF8.GetBytes(reader1.ReadOuterXml());
     }
     if (buffer.Length < this.MinMessageSize)
     {
         sourceMessage.Close();
         return messageBuffer.CreateMessage();
     }
     byte[] compressedData = DataCompressor.Compress(buffer);
     string copressedBody = CreateCompressedBody(compressedData);
     XmlTextReader reader = new XmlTextReader(new StringReader(copressedBody), new NameTable());
     Message compressedMessage = Message.CreateMessage(sourceMessage.Version, null, (XmlReader)reader);
     compressedMessage.Headers.CopyHeadersFrom(sourceMessage);
     compressedMessage.Properties.CopyProperties(sourceMessage.Properties);
     compressedMessage.AddCompressionHeader(this.DataCompressor.Algorithm);
     sourceMessage.Close();
     return compressedMessage;
 }
开发者ID:huoxudong125,项目名称:WCF-Demo,代码行数:25,代码来源:MessageCompressor.cs

示例6: BeforeSendReply

        public void BeforeSendReply(ref Message reply, object correlationState)
        {
            try
            {
                if (reply == null || reply.IsFault || reply.IsEmpty)
                {
                    return;
                }

                var buf = reply.CreateBufferedCopy(int.MaxValue);

                reply = buf.CreateMessage();
                using (MemoryStream ms = new MemoryStream())
                using (var memWriter = XmlDictionaryWriter.CreateTextWriter(ms))
                {
                    buf.CreateMessage().WriteMessage(memWriter);
                    memWriter.Flush();
                    try
                    {
                        LogActionCall(ms.Position, "Reply");
                    }
                    catch (Exception exception)
                    {
                        _log.Error(exception);
                    }
                }

                reply = buf.CreateMessage();
            }
            catch (Exception exception)
            {
                _log.Error(exception);
                throw;
            }
        }
开发者ID:amoraller,项目名称:AptekaAutoOrder,代码行数:35,代码来源:Interceptor.cs

示例7: BeforeSendRequest

 public object BeforeSendRequest(ref Message request, IClientChannel channel)
 {
     MessageBuffer buffer = request.CreateBufferedCopy(Int32.MaxValue);
     request = buffer.CreateMessage();
     Console.WriteLine("Sending:\n{0}", buffer.CreateMessage().ToString());
     return request;
 }
开发者ID:gitlabuser,项目名称:warehouse,代码行数:7,代码来源:ConsoleOutputBehavior.cs

示例8: AfterReceiveRequest

 public object AfterReceiveRequest(ref Message request, IClientChannel channel, InstanceContext instanceContext)
 {
     MessageBuffer buffer = request.CreateBufferedCopy(Int32.MaxValue);
     request = buffer.CreateMessage();
     Console.WriteLine("Received:\n{0}", buffer.CreateMessage());
     return null;
 }
开发者ID:jcde,项目名称:WCF,代码行数:7,代码来源:ConsoleOutputMessageInspector.cs

示例9: Process

 public void Process(int code, string text, Message message)
 {
     _code = code;
     _text = text;
     _buffer = message.CreateBufferedCopy(Int32.MaxValue);
     _ev.Set();
 }
开发者ID:ronybot,项目名称:MessageBus,代码行数:7,代码来源:MandatoryTest.cs

示例10: ReadMessageAndNotDestroyOriginal

        public static string ReadMessageAndNotDestroyOriginal(ref Message message)
        {
            var bufferedCopy = message.CreateBufferedCopy(int.MaxValue);
            message = bufferedCopy.CreateMessage();

            var toRead = bufferedCopy.CreateMessage();
            return toRead.GetReaderAtBodyContents().ReadOuterXml();
        }
开发者ID:AzaelCicero,项目名称:Wse3ContractClient,代码行数:8,代码来源:MessageTools.cs

示例11: LogMessage

        private Message LogMessage(Message original, Action<string> log)
        {
            // Need to create a copy as if a stream we can't transmit once we serialize
            var buffer = original.CreateBufferedCopy(int.MaxValue);
            log(buffer.MessageContent());

            return buffer.CreateMessage();
        }
开发者ID:RustyF,项目名称:EnergyTrading-Core,代码行数:8,代码来源:ClientMessageLogger.cs

示例12: AfterReceiveRequest

 public object AfterReceiveRequest(
     ref Message request, IClientChannel channel,
     InstanceContext instanceContext)
 {
     request =
            TraceMessage(request.CreateBufferedCopy(int.MaxValue));
     return null;
 }
开发者ID:ah16269,项目名称:rest-web-api-wcf,代码行数:8,代码来源:MyMessageInspector.cs

示例13: AfterReceiveReply

		public void AfterReceiveReply (ref Message reply, object correlationState)
		{
			MessageBuffer buf = reply.CreateBufferedCopy (0x10000);
			reply = buf.CreateMessage ();
			using (XmlWriter w = XmlWriter.Create (Console.Error, s)) {
				buf.CreateMessage ().WriteMessage (w);
			}
			Console.Error.WriteLine ("======================");
		}
开发者ID:alesliehughes,项目名称:olive,代码行数:9,代码来源:Inspector.cs

示例14: BeforeSendRequest

        public object BeforeSendRequest(ref Message request, IClientChannel channel)
        {
            MessageBuffer buffer = request.CreateBufferedCopy(Int32.MaxValue);
            request = buffer.CreateMessage();
            Message msg = buffer.CreateMessage();
            ASCIIEncoding encoder = new ASCIIEncoding();

            var sb = new StringBuilder();
            var xmlWriter = XmlWriter.Create(sb, new XmlWriterSettings
            {
                OmitXmlDeclaration = true
            });
            var writer = XmlDictionaryWriter.CreateDictionaryWriter(xmlWriter);
            msg.WriteStartEnvelope(writer);
            msg.WriteStartBody(writer);
            msg.WriteBodyContents(writer);
            xmlWriter.WriteEndElement();
            xmlWriter.WriteEndElement();
            writer.Flush();

            string body = sb.ToString().Replace(" />", "/>");

            byte[] xmlByte = encoder.GetBytes(body);
            SHA1CryptoServiceProvider sha1Crypto = new SHA1CryptoServiceProvider();
            string hash = BitConverter.ToString(sha1Crypto.ComputeHash(xmlByte)).Replace("-", "");
            string hashedContent = hash.ToLower();

            //assign values to hashing and header variables
            string time = DateTime.UtcNow.ToString("yyyy-MM-ddTHH:mm:ssZ");
            string hashData = "POST\ntext/xml; charset=utf-8\n" + hashedContent + "\n" + time + "\n/transaction/v12";
            //hmac sha1 hash with key + hash_data
            HMAC hmacSha1 = new HMACSHA1(Encoding.UTF8.GetBytes(_hmac)); //key
            byte[] hmacData = hmacSha1.ComputeHash(Encoding.UTF8.GetBytes(hashData)); //data
            //base64 encode on hmac_data
            string base64Hash = Convert.ToBase64String(hmacData);

            HttpRequestMessageProperty httpRequestMessage;
            object httpRequestMessageObject;

            if (request.Properties.TryGetValue(HttpRequestMessageProperty.Name, out httpRequestMessageObject))
            {
                httpRequestMessage = httpRequestMessageObject as HttpRequestMessageProperty;
                httpRequestMessage.Headers["X-GGe4-Content-SHA1"] = hashedContent;
                httpRequestMessage.Headers["X-GGe4-Date"] = time;
                httpRequestMessage.Headers["Authorization"] = "GGE4_API " + _keyId + ":" + base64Hash;
            }
            else
            {
                httpRequestMessage = new HttpRequestMessageProperty();
                httpRequestMessage.Headers["X-GGe4-Content-SHA1"] = hashedContent;
                httpRequestMessage.Headers["X-GGe4-Date"] = time;
                httpRequestMessage.Headers["Authorization"] = "GGE4_API " + _keyId + ":" + base64Hash;
                request.Properties.Add(HttpRequestMessageProperty.Name, httpRequestMessage);
            }
            return null;
        }
开发者ID:rvydhya,项目名称:Payeezy,代码行数:56,代码来源:HmacHeaderInspector.cs

示例15: BeforeSendReply

 public void BeforeSendReply(ref Message reply, object correlationState)
 {
     var logger = ObjectFactory.GetInstance<ILogger>();
     MessageBuffer buffer = reply.CreateBufferedCopy(int.MaxValue);
     var newResult = buffer.CreateMessage();
     string message = buffer.CreateMessage().ToString();
     logger.Write("Outgoing Message", message);
     logger.PersistLog();
     reply = newResult;
 }
开发者ID:josh28,项目名称:TaskMaster,代码行数:10,代码来源:CustomMessageInspector.cs


注:本文中的Message.CreateBufferedCopy方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。