本文整理汇总了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;
}
示例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);
}
示例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;
}
示例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();
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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);
}
示例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();
}
示例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);
};
}
示例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);
}
}
示例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);
}
示例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;
}
示例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>();
}