本文整理汇总了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);
}
示例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;
}
示例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");
}
}
}
示例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;
}
示例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;
}
示例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;
}
}
示例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;
}
示例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;
}
示例9: Process
public void Process(int code, string text, Message message)
{
_code = code;
_text = text;
_buffer = message.CreateBufferedCopy(Int32.MaxValue);
_ev.Set();
}
示例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();
}
示例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();
}
示例12: AfterReceiveRequest
public object AfterReceiveRequest(
ref Message request, IClientChannel channel,
InstanceContext instanceContext)
{
request =
TraceMessage(request.CreateBufferedCopy(int.MaxValue));
return null;
}
示例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 ("======================");
}
示例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;
}
示例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;
}