本文整理汇总了C#中System.Globalization.Message.Close方法的典型用法代码示例。如果您正苦于以下问题:C# Message.Close方法的具体用法?C# Message.Close怎么用?C# Message.Close使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Globalization.Message
的用法示例。
在下文中一共展示了Message.Close方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: IntroduceErrorToMessage
private void IntroduceErrorToMessage(ref Message message)
{
XmlDocument doc = new XmlDocument();
doc.Load(message.GetReaderAtBodyContents());
XmlNamespaceManager nsManager = new XmlNamespaceManager(doc.NameTable);
nsManager.AddNamespace("tempuri", "http://tempuri.org/");
XmlElement xNode = doc.SelectSingleNode("//tempuri:x", nsManager) as XmlElement;
XmlText xValue = xNode.FirstChild as XmlText;
xValue.Value = (double.Parse(xValue.Value, CultureInfo.InvariantCulture) + 1).ToString(CultureInfo.InvariantCulture);
MemoryStream ms = new MemoryStream();
XmlWriterSettings writerSettings = new XmlWriterSettings
{
CloseOutput = false,
OmitXmlDeclaration = true,
Encoding = Encoding.UTF8,
};
XmlWriter writer = XmlWriter.Create(ms, writerSettings);
doc.WriteTo(writer);
writer.Close();
ms.Position = 0;
XmlReader reader = XmlReader.Create(ms);
Message newMessage = Message.CreateMessage(message.Version, null, reader);
newMessage.Headers.CopyHeadersFrom(message);
newMessage.Properties.CopyProperties(message.Properties);
message.Close();
message = newMessage;
}
示例2: SendMessageToNeighbor
//this method takes care of closing the message.
void SendMessageToNeighbor(IPeerNeighbor neighbor, Message message, PeerMessageHelpers.CleanupCallback cleanupCallback)
{
bool fatal = false;
try
{
neighbor.Send(message);
}
catch (Exception e)
{
if (Fx.IsFatal(e))
{
fatal = true;
throw;
}
if (e is CommunicationException ||
e is QuotaExceededException ||
e is ObjectDisposedException ||
e is TimeoutException)
{
DiagnosticUtility.TraceHandledException(e, TraceEventType.Information);
// Message failed to transmit due to quota exceeding or channel failure
if (cleanupCallback != null)
{
cleanupCallback(neighbor, PeerCloseReason.InternalFailure, e);
}
}
else
{
throw;
}
}
finally
{
if (!fatal)
message.Close();
}
}
示例3: EncodeMessage
// Address the Message and serialize it into a byte array.
ArraySegment<byte> EncodeMessage(Message message)
{
try
{
this.RemoteAddress.ApplyTo(message);
return encoder.WriteMessage(message, maxBufferSize, bufferManager);
}
finally
{
// we've consumed the message by serializing it, so clean up
message.Close();
}
}
示例4: ProvideFault
public void ProvideFault(Exception error, MessageVersion version, ref Message fault)
{
HttpResponseMessageProperty responseProperty;
if (fault == null)
{
FaultCode code = new FaultCode(FaultCodeConstants.Codes.InternalServiceFault, FaultCodeConstants.Namespaces.NetDispatch);
code = FaultCode.CreateReceiverFaultCode(code);
string action = FaultCodeConstants.Actions.NetDispatcher;
MessageFault innerFault;
innerFault = MessageFault.CreateFault(code, new FaultReason(error.Message, CultureInfo.CurrentCulture), new ExceptionDetail(error));
fault = Message.CreateMessage(version, action, new JsonFaultBodyWriter(innerFault, this.includeExceptionDetailInFaults));
responseProperty = new HttpResponseMessageProperty();
fault.Properties.Add(HttpResponseMessageProperty.Name, responseProperty);
}
else
{
MessageFault innerFault = MessageFault.CreateFault(fault, TransportDefaults.MaxFaultSize);
Message newMessage = Message.CreateMessage(version, fault.Headers.Action, new JsonFaultBodyWriter(innerFault, this.includeExceptionDetailInFaults));
newMessage.Headers.To = fault.Headers.To;
newMessage.Properties.CopyProperties(fault.Properties);
object property = null;
if (newMessage.Properties.TryGetValue(HttpResponseMessageProperty.Name, out property))
{
responseProperty = (HttpResponseMessageProperty)property;
}
else
{
responseProperty = new HttpResponseMessageProperty();
newMessage.Properties.Add(HttpResponseMessageProperty.Name, responseProperty);
}
fault.Close();
fault = newMessage;
}
responseProperty.Headers.Add(HttpResponseHeader.ContentType, outgoingContentType);
responseProperty.Headers.Add(JsonGlobals.jsonerrorString, JsonGlobals.trueString);
responseProperty.StatusCode = System.Net.HttpStatusCode.InternalServerError;
object bodyFormatPropertyObject;
if (fault.Properties.TryGetValue(WebBodyFormatMessageProperty.Name, out bodyFormatPropertyObject))
{
WebBodyFormatMessageProperty bodyFormatProperty = bodyFormatPropertyObject as WebBodyFormatMessageProperty;
if ((bodyFormatProperty == null) ||
(bodyFormatProperty.Format != WebContentFormat.Json))
{
fault.Properties[WebBodyFormatMessageProperty.Name] = WebBodyFormatMessageProperty.JsonProperty;
}
}
else
{
fault.Properties.Add(WebBodyFormatMessageProperty.Name, WebBodyFormatMessageProperty.JsonProperty);
}
}
示例5: BeginSend
public IAsyncResult BeginSend(object registrant, Message message, Uri via, ITransportFactorySettings settings, TimeSpan timeout, AsyncCallback callback, object state, SecurityProtocol securityProtocol)
{
TimeoutHelper helper = new TimeoutHelper(timeout);
MessageBuffer encodedMessage = null;
Message message2 = null;
ulong maxValue = ulong.MaxValue;
PeerMessagePropagation localAndRemote = PeerMessagePropagation.LocalAndRemote;
int messageSize = -1;
SendAsyncResult result = new SendAsyncResult(callback, state);
AsyncCallback callback2 = Fx.ThunkCallback(new AsyncCallback(result.OnFloodComplete));
try
{
PeerFlooder flooder;
byte[] primarySignatureValue;
lock (this.ThisLock)
{
this.ThrowIfNotOpen();
flooder = this.flooder;
}
int maxBufferSize = (int) Math.Min(this.maxReceivedMessageSize, settings.MaxReceivedMessageSize);
Guid guid = this.ProcessOutgoingMessage(message, via);
this.SecureOutgoingMessage(ref message, via, timeout, securityProtocol);
if (message is SecurityAppliedMessage)
{
ArraySegment<byte> buffer = this.encoder.WriteMessage(message, 0x7fffffff, this.bufferManager);
message2 = this.encoder.ReadMessage(buffer, this.bufferManager);
primarySignatureValue = (message as SecurityAppliedMessage).PrimarySignatureValue;
messageSize = buffer.Count;
}
else
{
message2 = message;
primarySignatureValue = guid.ToByteArray();
}
encodedMessage = message2.CreateBufferedCopy(maxBufferSize);
string contentType = settings.MessageEncoderFactory.Encoder.ContentType;
if (this.messagePropagationFilter != null)
{
using (Message message3 = encodedMessage.CreateMessage())
{
localAndRemote = ((IPeerNodeMessageHandling) this).DetermineMessagePropagation(message3, PeerMessageOrigination.Local);
}
}
if (((localAndRemote & PeerMessagePropagation.Remote) != PeerMessagePropagation.None) && (maxValue == 0L))
{
localAndRemote &= ~PeerMessagePropagation.Remote;
}
IAsyncResult result2 = null;
if ((localAndRemote & PeerMessagePropagation.Remote) != PeerMessagePropagation.None)
{
result2 = flooder.BeginFloodEncodedMessage(primarySignatureValue, encodedMessage, helper.RemainingTime(), callback2, null);
if (System.ServiceModel.DiagnosticUtility.ShouldTraceVerbose)
{
TraceUtility.TraceEvent(TraceEventType.Verbose, 0x4003e, System.ServiceModel.SR.GetString("TraceCodePeerChannelMessageSent"), this, message);
}
}
else
{
result2 = new CompletedAsyncResult(callback2, null);
}
if ((localAndRemote & PeerMessagePropagation.Local) != PeerMessagePropagation.None)
{
using (Message message4 = encodedMessage.CreateMessage())
{
int i = message4.Headers.FindHeader("Security", "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd");
if (i >= 0)
{
message4.Headers.AddUnderstood(i);
}
using (MessageBuffer buffer3 = message4.CreateBufferedCopy(maxBufferSize))
{
this.DeliverMessageToClientChannels(registrant, buffer3, via, message.Headers.To, contentType, messageSize, -1, null);
}
}
}
result.OnLocalDispatchComplete(result);
}
finally
{
message.Close();
if (message2 != null)
{
message2.Close();
}
if (encodedMessage != null)
{
encodedMessage.Close();
}
}
return result;
}
示例6: SendMessageToNeighbor
private void SendMessageToNeighbor(IPeerNeighbor neighbor, Message message, PeerMessageHelpers.CleanupCallback cleanupCallback)
{
bool flag = false;
try
{
neighbor.Send(message);
}
catch (Exception exception)
{
if (Fx.IsFatal(exception))
{
flag = true;
throw;
}
if ((!(exception is CommunicationException) && !(exception is QuotaExceededException)) && (!(exception is ObjectDisposedException) && !(exception is TimeoutException)))
{
throw;
}
DiagnosticUtility.ExceptionUtility.TraceHandledException(exception, TraceEventType.Information);
if (cleanupCallback != null)
{
cleanupCallback(neighbor, PeerCloseReason.InternalFailure, exception);
}
}
finally
{
if (!flag)
{
message.Close();
}
}
}
示例7: ConfigureRequestMessage
private static Message ConfigureRequestMessage(Message message)
{
if (message == null)
{
return null;
}
HttpRequestMessageProperty requestProperty = message.GetHttpRequestMessageProperty();
if (requestProperty == null)
{
throw new InvalidOperationException(
string.Format(
CultureInfo.CurrentCulture,
SR.RequestMissingHttpRequestMessageProperty,
HttpRequestMessageProperty.Name,
typeof(HttpRequestMessageProperty).FullName));
}
Uri uri = message.Headers.To;
if (uri == null)
{
throw new InvalidOperationException(SR.RequestMissingToHeader);
}
HttpRequestMessage httpRequestMessage = message.ToHttpRequestMessage();
if (httpRequestMessage == null)
{
httpRequestMessage = new HttpRequestMessage();
httpRequestMessage.Content = new StringContent(String.Empty);
httpRequestMessage.Content.Headers.ContentLength = 0;
message.Close();
message = httpRequestMessage.ToMessage();
}
else
{
message.Headers.Clear();
message.Properties.Clear();
httpRequestMessage.Headers.Clear();
httpRequestMessage.GetProperties().Clear();
}
message.Headers.To = uri;
httpRequestMessage.RequestUri = uri;
httpRequestMessage.Method = new HttpMethod(requestProperty.Method);
foreach (var headerName in requestProperty.Headers.AllKeys)
{
if (headerName.StartsWith("content-", StringComparison.OrdinalIgnoreCase) ||
headerName.Equals("Allow", StringComparison.OrdinalIgnoreCase) ||
headerName.Equals("Expires") ||
headerName.Equals("Expires", StringComparison.OrdinalIgnoreCase))
{
httpRequestMessage.Content.Headers.Remove(headerName);
httpRequestMessage.Content.Headers.Add(headerName, requestProperty.Headers[headerName]);
continue;
}
httpRequestMessage.Headers.Remove(headerName);
httpRequestMessage.Headers.Add(headerName, requestProperty.Headers[headerName]);
}
return message;
}