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


C# Channels.BufferManager类代码示例

本文整理汇总了C#中System.ServiceModel.Channels.BufferManager的典型用法代码示例。如果您正苦于以下问题:C# BufferManager类的具体用法?C# BufferManager怎么用?C# BufferManager使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: WriteMessage

        public override ArraySegment<byte> WriteMessage(Message message,
      int maxMessageSize, BufferManager bufferManager, int messageOffset)
        {
            String bodyContent = null;

              lastMessage = message.Headers.Action;

              XmlDictionaryReader reader = message.GetReaderAtBodyContents();
              while (reader.Read())
              {
            if (reader.Name == "request")
            {
              bodyContent = reader.ReadElementContentAsString();
              break;
            }
              }
              reader.Close();

              byte[] messageBytes = System.Text.Encoding.UTF8.GetBytes(bodyContent);

              int totalLength = messageBytes.Length + messageOffset;
              byte[] totalBytes = bufferManager.TakeBuffer(totalLength);
              Array.Copy(messageBytes, 0,
            totalBytes, messageOffset, messageBytes.Length);

              ArraySegment<byte> buffer =
            new ArraySegment<byte>(
              totalBytes, messageOffset, messageBytes.Length);

              return buffer;
        }
开发者ID:gitlabuser,项目名称:warehouse,代码行数:31,代码来源:SerialMessageEncoder.cs

示例2: ReadMessage

 public override Message ReadMessage(ArraySegment<byte> buffer, BufferManager bufferManager, string contentType)
 {
     var msgContents = new byte[buffer.Count];
     Array.Copy(buffer.Array, buffer.Offset, msgContents, 0, msgContents.Length);
     var message = new UTF8Encoding().GetString(msgContents);
     var reader = XmlReader.Create(new MemoryStream(msgContents));
     var xmlDocument = new XmlDocument();
     xmlDocument.Load(reader);
     var elementsByTagName = xmlDocument.GetElementsByTagName("Envelope", Soap11Namespace);
     if (elementsByTagName.Count == 0)
         throw new XmlException("Не найден узел Envelope");
     var prefixOfNamespace = elementsByTagName[0].GetPrefixOfNamespace(Soap11Namespace);
     if (string.IsNullOrEmpty(prefixOfNamespace))
         throw new XmlException(string.Format("Не найден префикс пространста имен {0}", Soap11Namespace));
     LogMessage(xmlDocument, true);
     // Убираем actors из входящего сообщения
     message = message.Replace(prefixOfNamespace + ":mustUnderstand=\"1\"", "");
     message = message.Replace(prefixOfNamespace + ":actor=\"" + SmevActor + "\"", "");
     var bytes = new UTF8Encoding().GetBytes(message.Replace(prefixOfNamespace + ":actor=\"" + RecipientActor + "\"", ""));
     var length = bytes.Length;
     var array = bufferManager.TakeBuffer(length);
     Array.Copy(bytes, 0, array, 0, length);
     buffer = new ArraySegment<byte>(array, 0, length);
     return _innerEncoder.ReadMessage(buffer, bufferManager, contentType);
 }
开发者ID:aanufriyev,项目名称:SmevWCFService,代码行数:25,代码来源:SMEVTextMessageEncoder.cs

示例3: WriteMessage

        public override ArraySegment<byte> WriteMessage(Message message, int maxMessageSize, BufferManager bufferManager, int messageOffset)
        {
            ArraySegment<byte> messageBuffer;
            byte[] writeBuffer = null;

            int messageLength;
            using (MemoryStream stream = new MemoryStream())
            {
                using (XmlWriter writer = XmlWriter.Create(stream, _writerSettings))
                {
                    message.WriteMessage(writer);
                }

                // TryGetBuffer is the preferred path but requires 4.6
                //stream.TryGetBuffer(out messageBuffer);
                writeBuffer = stream.ToArray();
                messageBuffer = new ArraySegment<byte>(writeBuffer);

                messageLength = (int)stream.Position;
            }

            int totalLength = messageLength + messageOffset;
            byte[] totalBytes = bufferManager.TakeBuffer(totalLength);
            Array.Copy(messageBuffer.Array, 0, totalBytes, messageOffset, messageLength);

            ArraySegment<byte> byteArray = new ArraySegment<byte>(totalBytes, messageOffset, messageLength);
            return byteArray;
        }
开发者ID:weshaggard,项目名称:wcf,代码行数:28,代码来源:CustomTextMessageEncoder.cs

示例4: FileRequestChannel

 public FileRequestChannel(BufferManager bufferManager, MessageEncoderFactory encoderFactory, EndpointAddress address,
     FileRequestChannelFactory parent, Uri via)
     : base(bufferManager, encoderFactory, address, parent, parent.MaxReceivedMessageSize)
 {
     this.via = via;
     this.writeLock = new object();
 }
开发者ID:dmetzgar,项目名称:custom-transport-channel,代码行数:7,代码来源:FileRequestChannel.cs

示例5: UdpSocketListener

 // Listen sockets have been created.
 public UdpSocketListener(List<Socket> listenSockets, int maxBufferPoolSize, int maxMessageSize, DataReceivedCallback dataReceivedCallback)
 {
     this.listenSockets = listenSockets;
     this.maxMessageSize = maxMessageSize;
     this.bufferManager = BufferManager.CreateBufferManager(maxBufferPoolSize, maxMessageSize);
     this.dataReceivedCallback = dataReceivedCallback;
 }
开发者ID:tian1ll1,项目名称:WPF_Examples,代码行数:8,代码来源:UdpSocketListener.cs

示例6: ReadMessage

 public override Message ReadMessage(ArraySegment<byte> buffer, BufferManager bufferManager, string contentType)
 {
     ArraySegment<byte> decompressedBuffer = DecompressBuffer(buffer, bufferManager);
     Message returnMessage = _messageEncoder.ReadMessage(decompressedBuffer, bufferManager);
     returnMessage.Properties.Encoder = this;
     return returnMessage;
 }
开发者ID:Nickymaco,项目名称:UwaySoftWCDMA,代码行数:7,代码来源:CompressionMessageEncoder.cs

示例7: WriteMessage

 public override ArraySegment<byte> WriteMessage(Message message, int maxMessageSize, BufferManager bufferManager, int messageOffset)
 {
     ArraySegment<byte> buffer = innerEncoder.WriteMessage(message, maxMessageSize, bufferManager, messageOffset);
     bindingElement.WriteCount++;
     bindingElement.WriteBytes += buffer.Count;
     return buffer;
 }
开发者ID:JackFong,项目名称:GenericWcfServiceHostAndClient,代码行数:7,代码来源:CountingEncoder.cs

示例8: ReadMessage

 public override Message ReadMessage(ArraySegment<byte> buffer, BufferManager bufferManager, string contentType)
 {
     Message message = this.innerEncoder.ReadMessage(buffer, bufferManager);
     bindingElement.ReadCount++;
     bindingElement.ReadBytes += buffer.Count;
     return message;
 }
开发者ID:JackFong,项目名称:GenericWcfServiceHostAndClient,代码行数:7,代码来源:CountingEncoder.cs

示例9: SizedTcpReplyChannel

 public SizedTcpReplyChannel(MessageEncoder encoder, BufferManager bufferManager, Uri localAddress, Socket socket, ChannelManagerBase channelManager)
     : base(encoder, bufferManager, channelManager)
 {
     this.localAddress = localAddress;
     this.socket = socket;
     this.InitializeSocket(socket);
 }
开发者ID:GusLab,项目名称:WCFSamples,代码行数:7,代码来源:SizedTcpReplyChannel.cs

示例10: FileReplyChannel

 public FileReplyChannel(BufferManager bufferManager, MessageEncoderFactory encoderFactory, EndpointAddress address,
     FileReplyChannelListener parent)
     : base(bufferManager, encoderFactory, address, parent, parent.MaxReceivedMessageSize)
 {
     this.localAddress = address;
     this.readLock = new object();
 }
开发者ID:dmetzgar,项目名称:custom-transport-channel,代码行数:7,代码来源:FileReplyChannel.cs

示例11: MessageBusInputChannel

        public MessageBusInputChannel(
            BufferManager bufferManager, MessageEncoderFactory encoder, ChannelManagerBase parent,
            EndpointAddress localAddress,
            IBus bus)
            : base(bufferManager, encoder, parent)
        {
            _localAddress = localAddress;
            _bus = bus;
            _aLock = new object();

            _tryReceiveDelegate = (TimeSpan timeout, out Message message) =>
            {
                message = null;
                try
                {
                    var requestMessage = _bus.Receive(true, null);
                    if (requestMessage != null)
                    {
                        message = GetWcfMessageFromString(requestMessage.Content);
                        OnAfterTryReceive(requestMessage);
                    }
                }
                catch (Exception ex)
                {
                    throw new CommunicationException(ex.Message, ex);
                }
                return true;
            };

            _receiveDelegate = (TimeSpan timeout) =>
            {
                var requestMessage = _bus.Receive(false, ChannelID);
                return GetWcfMessageFromString(requestMessage.Content);
            };
        }
开发者ID:shaunxu,项目名称:roma,代码行数:35,代码来源:MessageBusInputChannel.cs

示例12: WriteMessage

        public override ArraySegment<byte> WriteMessage(Message message, int maxMessageSize, BufferManager bufferManager, int messageOffset)
        {
            if (message.Properties.ContainsKey(HttpRequestMessageProperty.Name))
            {
                HttpRequestMessageProperty httpMessage = message.Properties[HttpRequestMessageProperty.Name] as HttpRequestMessageProperty;

                if (httpMessage != null && httpMessage.Method == "POST")
                {
                    ArraySegment<byte> innerMessage = _encoder.WriteMessage(message, maxMessageSize, bufferManager, messageOffset);

                    byte[] encodedMessage = Encoding.UTF8.GetBytes(String.Concat("xml=", HttpUtility.UrlEncode(Encoding.UTF8.GetString(innerMessage.Array, 0, innerMessage.Count))));

                    bufferManager.ReturnBuffer(innerMessage.Array);

                    byte[] buffer = bufferManager.TakeBuffer(encodedMessage.Length);

                    Array.Copy(encodedMessage, buffer, encodedMessage.Length);

                    bufferManager.ReturnBuffer(buffer);

                    return new ArraySegment<byte>(buffer, messageOffset, encodedMessage.Length);
                }
                else
                {
                    return _encoder.WriteMessage(message, maxMessageSize, bufferManager, messageOffset);
                }
            }
            else
            {
                return _encoder.WriteMessage(message, maxMessageSize, bufferManager, messageOffset);
            }
        }
开发者ID:Dozey,项目名称:XeroAPI,代码行数:32,代码来源:XeroMessageEncoder.cs

示例13: ReadMessage

        /// <inheritdoc />
        public override Message ReadMessage(ArraySegment<byte> buffer, BufferManager bufferManager, string contentType)
        {
            // Treat the alternate as native
            if (IsAlternateContent(contentType))
            {
                // HACK: Should see if we have a declr or some xml
               contentType = this.contentType;
            }

            var msgContents = new byte[buffer.Count];
            Array.Copy(buffer.Array, buffer.Offset, msgContents, 0, msgContents.Length);
            bufferManager.ReturnBuffer(buffer.Array);

            // Most interoperable to include the xml declaration
            writerSettings.OmitXmlDeclaration = false;

            // Save the encoding for when we write the response
            writerSettings.Encoding = msgContents.GetEncoding(contentType);
            var xmlDeclEncoding = msgContents.GetXmlDeclEncoding(writerSettings.Encoding);

            // Check if the two encodings align
            if (xmlDeclEncoding != null && xmlDeclEncoding.WebName == writerSettings.Encoding.WebName)
            {
                // Need to recode
                msgContents = Encoding.Convert(writerSettings.Encoding, xmlDeclEncoding, msgContents);
            }

            var stream = new MemoryStream(msgContents);
            return ReadMessage(stream, int.MaxValue);
        }
开发者ID:RustyF,项目名称:EnergyTrading-Core,代码行数:31,代码来源:CustomTextMessageEncoder.cs

示例14: WriteMessage

            public override ArraySegment<byte> WriteMessage(Message message, int maxMessageSize, BufferManager bufferManager, int messageOffset)
            {
                if (message == null)
                {
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentNullException("message"));
                }
                if (bufferManager == null)
                {
                    throw TraceUtility.ThrowHelperError(new ArgumentNullException("bufferManager"), message);
                }
                if (maxMessageSize < 0)
                {
                    throw TraceUtility.ThrowHelperError(new ArgumentOutOfRangeException("maxMessageSize", maxMessageSize,
                        SR2.GetString(SR2.ValueMustBeNonNegative)), message);
                }
                if (messageOffset < 0 || messageOffset > maxMessageSize)
                {
                    throw TraceUtility.ThrowHelperError(new ArgumentOutOfRangeException("messageOffset", messageOffset,
                        SR2.GetString(SR2.JsonValueMustBeInRange, 0, maxMessageSize)), message);
                }

                ThrowIfMismatchedMessageVersion(message);
                message.Properties.Encoder = this;
                BufferedMessageWriter messageWriter = new WebScriptMetadataBufferedMessageWriter(this);
                ArraySegment<byte> messageData = messageWriter.WriteMessage(message, bufferManager, messageOffset, maxMessageSize);
                if (MessageLogger.LogMessagesAtTransportLevel)
                {
                    MessageLogger.LogMessage(ref message, MessageLoggingSource.TransportSend);
                }
                if (System.ServiceModel.Diagnostics.Application.TD.MessageWrittenByEncoderIsEnabled() && messageData != null)
                {
                    System.ServiceModel.Diagnostics.Application.TD.MessageWrittenByEncoder(EventTraceActivityHelper.TryExtractActivity(message), messageData.Count, this);
                }
                return messageData;
            }
开发者ID:nlh774,项目名称:DotNetReferenceSource,代码行数:35,代码来源:WebScriptMetadataMessageEncoderFactory.cs

示例15: Acceptor

 public Acceptor(DistributorConfig config)
 {
     _bufferManager = BufferManager.CreateBufferManager(MaxBufferPoolSize, MaxBufferSize);
     _config = config;
     _listener = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
     _interactors = new Dictionary<Socket, Interactor>();
 }
开发者ID:rob-blackbourn,项目名称:TopicBus,代码行数:7,代码来源:Acceptor.cs


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