本文整理汇总了C#中MessageHeaders.GetHeader方法的典型用法代码示例。如果您正苦于以下问题:C# MessageHeaders.GetHeader方法的具体用法?C# MessageHeaders.GetHeader怎么用?C# MessageHeaders.GetHeader使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MessageHeaders
的用法示例。
在下文中一共展示了MessageHeaders.GetHeader方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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;
}
示例2: InspectHeaders
public void InspectHeaders(MessageHeaders messageHeaders)
{
try
{
var timestamp = messageHeaders.GetHeader<DateTime?>("time", SoapExtensionsNamespace);
_notifyCallback(timestamp);
}
catch (Exception)
{
_notifyCallback(null);
}
}
示例3: 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);
}
}
}
}
}
示例4: GetHeaderNullSerializer2
public void GetHeaderNullSerializer2 ()
{
MessageHeaders headers = new MessageHeaders (MessageVersion.Default);
string ns = "http://schemas.xmlsoap.org/ws/2004/08/addressing";
headers.Add (MessageHeader.CreateHeader ("Action", ns, "urn:foo"));
headers.GetHeader<string> ("Action", ns, (XmlObjectSerializer) null);
}