本文整理汇总了C#中MessageHeaders.GetReaderAtHeader方法的典型用法代码示例。如果您正苦于以下问题:C# MessageHeaders.GetReaderAtHeader方法的具体用法?C# MessageHeaders.GetReaderAtHeader怎么用?C# MessageHeaders.GetReaderAtHeader使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MessageHeaders
的用法示例。
在下文中一共展示了MessageHeaders.GetReaderAtHeader方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ExtractActivityAndCorrelationId
public static bool ExtractActivityAndCorrelationId(MessageHeaders headers, out Guid activityId, out Guid correlationId)
{
if (headers == null) throw new ArgumentNullException(nameof(headers));
activityId = Guid.Empty;
correlationId = Guid.Empty;
try
{
var index = headers.FindHeader("ActivityId", "http://schemas.microsoft.com/2004/09/ServiceModel/Diagnostics");
if (index >= 0)
{
using (var reader = headers.GetReaderAtHeader(index))
{
correlationId = new Guid(reader.GetAttribute("CorrelationId", null));
activityId = reader.ReadElementContentAsGuid();
return true;
}
}
}
catch
{
if (Debugger.IsAttached)
{
throw;
}
}
return false;
}
示例2: ApplySecurityAndWriteHeaders
public void ApplySecurityAndWriteHeaders(MessageHeaders headers, XmlDictionaryWriter writer, SecurityIdGenerator securityIdGenerator)
{
// There is no way to look through the headers attributes without changing the way
// Headers.WriterStartHeader / headers.writeHeadercontents writes the header
// So i'm using a copy that I can change without worries.
MessageHeaders copyHeaders = new MessageHeaders(headers);
for (int i = 0; i < headers.Count; i++)
{
MessageHeaderInfo header = headers[i];
// We are not supporting another d:Security header, throw if there is already one in the message
if (this.IsSecurityElement(header))
{
throw new ArgumentException("The message already contains a d:security header.");
}
if (this.ShouldProtectHeader(header))
{
string headerId;
bool idInserted;
this.GetHeaderId(copyHeaders.GetReaderAtHeader(i), securityIdGenerator, true, out headerId, out idInserted);
// Add a reference for this header
this.signer.AddReference(headers, i, writer, headerId, idInserted);
}
else
{
headers.WriteHeader(i, writer);
}
}
}
示例3: GetHeaderULong
public static ulong GetHeaderULong(MessageHeaders headers, int index)
{
ulong maxValue = ulong.MaxValue;
if (index >= 0)
{
using (XmlDictionaryReader reader = headers.GetReaderAtHeader(index))
{
maxValue = XmlConvert.ToUInt64(reader.ReadElementString());
}
headers.UnderstoodHeaders.Add(headers[index]);
}
return maxValue;
}
示例4: GetHeaderString
public static string GetHeaderString(MessageHeaders headers, string name, string ns)
{
string str = null;
int headerIndex = headers.FindHeader(name, ns);
if (headerIndex >= 0)
{
using (XmlDictionaryReader reader = headers.GetReaderAtHeader(headerIndex))
{
str = reader.ReadElementString();
}
headers.UnderstoodHeaders.Add(headers[headerIndex]);
}
return str;
}
示例5: GetHeaderUniqueId
public static UniqueId GetHeaderUniqueId(MessageHeaders headers, string name, string ns)
{
UniqueId id = null;
int headerIndex = headers.FindHeader(name, ns);
if (headerIndex >= 0)
{
using (XmlDictionaryReader reader = headers.GetReaderAtHeader(headerIndex))
{
id = reader.ReadElementContentAsUniqueId();
}
headers.UnderstoodHeaders.Add(headers[headerIndex]);
}
return id;
}
示例6: ReadFrom
public static TotalItemsCountEstimate ReadFrom(MessageHeaders messageHeaders)
{
TotalItemsCountEstimate result;
int index = messageHeaders.FindHeader(ElementName, ManagementNamespaces.Namespace);
if (index < 0)
{
return null;
}
using (XmlDictionaryReader readerAtHeader = messageHeaders.GetReaderAtHeader(index))
{
result = ReadFrom(readerAtHeader);
}
return result;
}
示例7: ReadFrom
public static ResourceUriHeader ReadFrom(MessageHeaders messageHeaders)
{
ResourceUriHeader result;
int index = messageHeaders.FindHeader(ElementName, ManagementNamespaces.Namespace);
if (index < 0)
{
return null;
}
using (XmlDictionaryReader readerAtHeader = messageHeaders.GetReaderAtHeader(index))
{
result = ReadFrom(readerAtHeader);
}
return result;
}
示例8: ReadFrom
public static IdentifierHeader ReadFrom(MessageHeaders messageHeaders)
{
IdentifierHeader result;
int index = messageHeaders.FindHeader(ElementName, EventingActions.Namespace);
if (index < 0)
{
return null;
}
using (XmlDictionaryReader readerAtHeader = messageHeaders.GetReaderAtHeader(index))
{
result = ReadFrom(readerAtHeader);
}
MessageHeaderInfo headerInfo = messageHeaders[index];
return result;
}
示例9: ReadFrom
public static FragmentTransferHeader ReadFrom(MessageHeaders messageHeaders)
{
FragmentTransferHeader result;
int index = messageHeaders.FindHeader(ElementName, ManagementNamespaces.Namespace);
if (index < 0)
{
return null;
}
using (XmlDictionaryReader readerAtHeader = messageHeaders.GetReaderAtHeader(index))
{
result = ReadFrom(readerAtHeader);
}
MessageHeaderInfo headerInfo = messageHeaders[index];
return result;
}
示例10: FindHeader
internal static PollingDuplexSession FindHeader(MessageHeaders headers)
{
PollingDuplexSession info = null;
try
{
int headerIndex = headers.FindHeader("Duplex", "http://schemas.microsoft.com/2008/04/netduplex");
if (headerIndex != -1)
{
info = ReadHeaderValue(headers.GetReaderAtHeader(headerIndex));
}
}
catch (XmlException)
{
}
return info;
}
示例11: ReadFrom
public static MaxEnvelopeSizeHeader ReadFrom(MessageHeaders messageHeaders)
{
MaxEnvelopeSizeHeader result;
int index = messageHeaders.FindHeader(ElementName, Const.ManagementNamespace);
if (index < 0)
{
return null;
}
using (XmlDictionaryReader readerAtHeader = messageHeaders.GetReaderAtHeader(index))
{
result = ReadFrom(readerAtHeader);
}
MessageHeaderInfo headerInfo = messageHeaders[index];
if (!messageHeaders.UnderstoodHeaders.Contains(headerInfo))
{
messageHeaders.UnderstoodHeaders.Add(headerInfo);
}
return result;
}
示例12: SetDataContract
/// <summary>
/// Set wellknown headers into the CallContext Thread slot
/// </summary>
/// <param name="headers">List of all message headers</param>
/// <param name="actor">Role (actor) of the headers. Note this is also the name of the assembly, where must be declared all CallContext Headers.</param>
public static void SetDataContract(MessageHeaders headers, string actor)
{
if (string.IsNullOrEmpty(actor))
{
try
{
// wellknown header LogicalWorkflowContext
LogicalWorkflowContext lwc = headers.GetHeader<LogicalWorkflowContext>("LogicalWorkflowContext", "RKiss.WorkflowRemoting", "WorkflowRemoting");
if(lwc == null)
throw new NullReferenceException("Deserializer failed for header 'LogicalWorkflowContext'");
// set data into the Thread slot
CallContext.SetData("LogicalWorkflowContext", lwc);
}
catch (Exception ex)
{
Trace.WriteLine(ex);
}
}
else
{
bool bDoneForLWC = false;
for (int ii = 0; ii < headers.Count; ii++)
{
string typeName = string.Concat(headers[ii].Namespace, ".", headers[ii].Name, ",", headers[ii].Actor);
if (!bDoneForLWC && typeName == "RKiss.WorkflowRemoting.LogicalWorkflowContext,WorkflowRemoting")
{
object lwc = headers.GetHeader<LogicalWorkflowContext>(ii);
if (lwc == null)
throw new NullReferenceException("Deserializer failed for header 'LogicalWorkflowContext'");
// set data into the Thread slot
CallContext.SetData("LogicalWorkflowContext", lwc);
// next header
bDoneForLWC = true;
continue;
}
else if (!string.IsNullOrEmpty(headers[ii].Actor) && string.Concat(actor, ",").Contains(string.Concat(headers[ii].Actor, ",")))
{
try
{
Type type = Type.GetType(typeName);
if (type == null)
throw new TypeLoadException(typeName);
// deserializer
DataContractSerializer dcs = new DataContractSerializer(type, headers[ii].Name, headers[ii].Namespace);
object data = dcs.ReadObject(headers.GetReaderAtHeader(ii), true);
if (data == null)
throw new NullReferenceException(string.Format("Deserializer failed for header '{0}'", headers[ii].Name));
// set data into the Thread slot
CallContext.SetData(headers[ii].Name, data);
}
catch (Exception ex)
{
Trace.WriteLine(ex);
}
}
}
}
}
示例13: GetReaderAtHeaderOutOfRange
public void GetReaderAtHeaderOutOfRange ()
{
MessageHeaders h = new MessageHeaders (MessageVersion.Default, 1);
h.GetReaderAtHeader (0);
}
示例14: GetHeaderULong
public static ulong GetHeaderULong(MessageHeaders headers, int index)
{
ulong result = PeerTransportConstants.MaxHopCount;
if (index >= 0)
{
using (XmlDictionaryReader reader = headers.GetReaderAtHeader(index))
{
result = XmlConvert.ToUInt64(reader.ReadElementString());
}
headers.UnderstoodHeaders.Add(headers[index]);
}
return result;
}