本文整理汇总了C#中MessageHeaders.FindHeader方法的典型用法代码示例。如果您正苦于以下问题:C# MessageHeaders.FindHeader方法的具体用法?C# MessageHeaders.FindHeader怎么用?C# MessageHeaders.FindHeader使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MessageHeaders
的用法示例。
在下文中一共展示了MessageHeaders.FindHeader方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: GetDataSignature
/// <summary>
/// Gets the data signature in the given message header collection
/// </summary>
/// <param name="headers">Message headers</param>
/// <returns>Data signature or Guid.Empty</returns>
public static Guid GetDataSignature(MessageHeaders headers)
{
Guid dataSignature = Guid.Empty;
int headerIndex = headers.FindHeader(Header.Name, Header.Namespace);
if (headerIndex != -1)
{
dataSignature = headers.GetHeader<Guid>(headerIndex);
}
return dataSignature;
}
示例3: ReadFrom
public static RequestTotalItemsCountEstimate ReadFrom(MessageHeaders messageHeaders)
{
int index = messageHeaders.FindHeader(ElementName, ManagementNamespaces.Namespace);
if (index < 0)
{
return null;
}
MessageHeaderInfo headerInfo = messageHeaders[index];
return new RequestTotalItemsCountEstimate();
}
示例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: 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;
}
示例6: 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;
}
示例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: RemoveHeader
/// <summary>
/// 删除消息头
/// </summary>
/// <param name="headers"></param>
/// <param name="index"></param>
internal static void RemoveHeader(MessageHeaders headers)
{
if (headers.FindHeader("HeaderContext", "session") >= 0)
headers.RemoveAt(headers.FindHeader("HeaderContext", "session"));
}
示例13: RemoveAppNameHeader
/// <summary>
/// 删除消息头
/// </summary>
/// <param name="headers"></param>
/// <param name="index"></param>
internal static void RemoveAppNameHeader(MessageHeaders headers)
{
if (headers.FindHeader("AppNameHeaderContext", "appnamesession") >= 0)
headers.RemoveAt(headers.FindHeader("AppNameHeaderContext", "appnamesession"));
}
示例14: MarkHeaderAsUnderstood
public static void MarkHeaderAsUnderstood(MessageHeaders headers, string localName, string ns)
{
int num = headers.FindHeader(localName, ns);
if (-1 != num)
{
if (!headers.UnderstoodHeaders.Contains(headers[num]))
{
headers.UnderstoodHeaders.Add(headers[num]);
}
return;
}
else
{
return;
}
}
示例15: BeforeSendRequestTest
public void BeforeSendRequestTest()
{
// Arrange.
const string HeaderName1 = "Header1";
const string HeaderName2 = "Header2";
const string HeaderNamespace = "TestNamespace";
const string Actor = "TestActor";
var oldHeader1 = MessageHeader.CreateHeader(HeaderName1, HeaderNamespace, "Test Value 1");
var oldHeader2 = MessageHeader.CreateHeader(HeaderName2, HeaderNamespace, "Test Value 2");
var operationContext = Mock.Create<OperationContext>();
Mock.Arrange(() => OperationContext.Current).Returns(operationContext);
var headerAttributes = new SoapHeaderAttributes
{
HeaderName = HeaderName2,
HeaderNamespace = HeaderNamespace,
MustUnderstand = true,
Actor = Actor,
Relay = true
};
var integrationExtension = new IntegrationServiceOperationContextExtension();
integrationExtension.HeaderAttributes.Add(headerAttributes);
var extensions = new ExtensionCollection<OperationContext>(operationContext) { integrationExtension };
Mock.Arrange(() => operationContext.Extensions).Returns(extensions);
var message = Mock.Create<Message>();
var messageHeaders = new MessageHeaders(MessageVersion.Soap11) { oldHeader1, oldHeader2 };
Mock.Arrange(() => message.Headers).Returns(messageHeaders);
var inspector = new IntegrationServiceMessageInspector();
// Act.
var newMessage = message;
inspector.BeforeSendRequest(ref newMessage, Mock.Create<IClientChannel>());
// Assert.
Assert.AreSame(message, newMessage);
Assert.AreEqual(2, messageHeaders.Count);
Assert.IsTrue(messageHeaders.Contains(oldHeader1));
Assert.IsFalse(messageHeaders.Contains(oldHeader2));
var index = messageHeaders.FindHeader(HeaderName2, HeaderNamespace, Actor);
var newHeader2 = (XmlElementMessageHeader)messageHeaders[index];
Assert.IsTrue(newHeader2.MustUnderstand);
Assert.AreEqual(Actor, newHeader2.Actor);
Assert.IsTrue(newHeader2.Relay);
// Exceptions.
Message nullMessage = null;
TestsHelper.VerifyThrow<ArgumentNullException>(() => inspector.BeforeSendRequest(ref nullMessage, Mock.Create<IClientChannel>()));
var message2 = Mock.Create<Message>();
TestsHelper.VerifyThrow<ArgumentNullException>(() => inspector.BeforeSendRequest(ref message2, null));
}