Display all messageHeader's values

戏子无情 提交于 2020-02-02 11:35:30

问题


I'd like to know what is the best way to display all MessageHeaders server side. Actually the only way I know is the following:

OperationContext.Current.IncomingMessageHeaders.GetHeader<T>(Name, Namespace)

That method is only for a known MessageHeader but I'd like to display their values in a loop.

Thank You


回答1:


The headers are loopable:

for (int i = 0; i < OperationContext.Current.IncomingMessageHeaders.Count; ++i)
{
    MessageHeaderInfo h = OperationContext.Current.IncomingMessageHeaders[i];
    // for any reference parameters with the correct name & namespace
    if (h.IsReferenceParameter && 
        h.Name == IDName && 
        h.Namespace == IDNamespace) 
    {
        // read the value of that header
        XmlReader xr = OperationContext.Current.IncomingMessageHeaders.GetReaderAtHeader(i);
        id = xr.ReadElementContentAsString();
    }
}

Found here



来源:https://stackoverflow.com/questions/5407440/display-all-messageheaders-values

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!