WCF read multiple 'identical' headers

464 views Asked by At

I'm having trouble reading multiple SOAP-headers with the same Name and Namespace. The usual

request.Headers.GetHeader<string>("Name", "Namespace")

throws an exception if there are multiple SOAP-Headers with the given name and namespace.

I've come up with the following solution, but I hope there is a more straightforward way, because this is a little bit too much if you ask me:

var list = request.Headers.ToList(); // .ToList() might not be neccessary...
var indexes = list.Select((x, i) => new { Idx = i, Obj = x })
    .Where(x => x.Obj.Name == "App" 
        && x.Obj.Namespace == SoapUtilities.NAMESPACE)
    .Select(x => x.Idx).ToList();
List<string> applist = new List<string>();

foreach (var idx in indexes)
{
    string app = request.Headers.GetHeader<string>(idx);
    applist.Add(app);
}

Of course I can do this:

request.Headers.Where(x=>x.Name = "App" 
    && x.Namespace = SoapUtilities.NAMESPACE).ToList();

... but that gives a list of MessageHeaderInfo and I cannot figure out how to get the payload of the SOAP-header easily out of it...

Kind regards,

Edwin.

0

There are 0 answers