2
我需要從我的WCF消息中獲取值。我的消息在調試以下值:使用XmlDictionaryReader從消息中獲取值
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
<s:Header>
<Action s:mustUnderstand="1" xmlns="http://schemas.microsoft.com/ws/2005/05/addressing/none">http://tempuri.org/IBrokerService/SaveAndPrint</Action>
</s:Header>
<s:Body>
<SaveAndPrint xmlns="http://tempuri.org/">
<contract xmlns:d4p1="http://schemas.datacontract.org/2004/07/BrokerService.Contracts" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
<d4p1:ContainerHistoryContracts i:nil="true" />
<!--Lots of nodes removed for brevity-->
<d4p1:CurrentBagId>123456</d4p1:CurrentBagId>
<!--Lots more nodes removed for brevity-->
<d4p1:WorkStation>TheNeededValue</d4p1:WorkStation>
</contract>
</SaveAndPrint>
</s:Body>
</s:Envelope>
但是儘量爲我可能,我不能使用XmlDictionaryReader得到d4p1:WorkStation
值。任何人都知道如何使用XmlDictionaryReader來做到這一點?
注:我試圖用TypedMessageConverter
,但所產生的clasess不具備的MessageContract
屬性(他們必須DataContract
雖然)
更新:我已經無法正常工作。但櫃面你想看到它,那就是:
// Load the message into an xml doc
var navigator = buffer.CreateNavigator();
MemoryStream memoryStream = new MemoryStream();
XmlWriter xmlWriter = XmlWriter.Create(memoryStream);
navigator.WriteSubtree(xmlWriter);
xmlWriter.Flush();
xmlWriter.Close();
memoryStream.Position = 0;
XDocument xdoc = XDocument.Load(XmlReader.Create(memoryStream));
var workstationElement =
xdoc.Descendants(XName.Get("StringValue",
@"/s:Envelope[@xmlns:s=""http://schemas.xmlsoap.org/soap/envelope/""]/s:Body/SaveAndPrint[@xmlns=""http://tempuri.org/""]/contract[@xmlns:d4p1=""http://schemas.datacontract.org/2004/07/BrokerService.Contracts""]/d4p1:WorkStation"));
什麼是你的XML解析的代碼是什麼樣子? – DVK
@DVK - 不知道我破碎的代碼會如何幫助,但我已經添加了它。 – Vaccano