I have to read element from Inbound Header...

I am assigning inbound header using WCF.InboundHeaders to a string....

now my problem is my inbounde header is looking like this

InboundHeaders

<headers><s:userid xmlns:s="http://www.w3.org/2003/05/soap-envelope">testuser</s:userid>

 <s:applicationid xmlns:s="http://www.w3.org/2003/05/soap-envelope">assistworkerweb</s:applicationid>

<a:Action s:mustUnderstand="1" xmlns:s="http://www.w3.org/2003/05/soap-envelope" xmlns:a="http://www.w3.org/2005/08/addressing">http://Request</a:Action><a:To s:mustUnderstand="1" xmlns:s="http://www.w3.org/2003/05/soap-envelope" xmlns:a="http://www.w3.org/2005/08/addressing">

Now i need to extract user id from it ..how to extract user id from it..

有帮助吗?

解决方案

You haven't mentioned where or how your string is stored (that is populated with your WCF.InboundHeaders), however I would use a simple fragment of XPath to extract the UserId. If you were extracting this using a C# helper, you could do something along the lines of (note, this is untested, however its pretty much there):

XmlDocument doc = new XmlDocument();
doc.Load([WCF.InboundHeaders Xml Fragment]);

// Create an XmlNamespaceManager to add 'soap-envelope' namespace
XmlNamespaceManager nsmgr = new XmlNamespaceManager(doc.NameTable);
nsmgr.AddNamespace("s", "http://www.w3.org/2003/05/soap-envelope");

// Select the UserId
XmlNode userId = doc.SelectSingleNode("/headers/s:userid", nsmgr);
Console.WriteLine(userId.InnerXml);

You may also want to serialize the Xml fragment into a .Net object and retrieve the UserId in that manner.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top