我需要使用服务跟踪查看器找到标签200,它看起来像这样!
<SOAP-ENV:Body xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" wsu:Id="id-14799">
<ns2:SendInvoice xmlns:ns2="http://www.zadrwan.com/services/" xmlns:ns3="http://www.zadrwan.com/services/DocumentSendTo" xmlns:ns4="http://www.zadrwan.com/services/VersionRequest">
<ns2:Response>200</ns2:Response>
<ns2:Comments>Success!.</ns2:Comments>
</ns2:SendInvoice>
运行Web服务时执行Trace并写一个E2ETraceEvent,第一个我不需要,但是第二个E2ETraceEvent(请求)是我需要的,而
我在此页面monitoring-and-reading-svclog-file
上找到了一些代码我的代码是这样的:
XmlReader reader = XmlReader.Create(stream, settings);
while (reader.Read())
{
switch (reader.NodeType)
{
case XmlNodeType.Element:
if (reader.Name == "E2ETraceEvent")
{
XmlReader subReader = reader.ReadSubtree();
while (subReader.Read())
{
switch (reader.NodeType)
{
case XmlNodeType.Element:
while (reader.Name == "Body")
{
Console.WriteLine(subReader.ReadOuterXml());
}
break;
}
}
}
break;
}
}
如何使用包含n2响应的标记捕获第二个?
答案 0 :(得分:0)
您需要添加名称空间。像这样:
using (XmlReader reader = XmlReader.Create(new StringReader(xml)))
{
XmlNamespaceManager nsmanager = new XmlNamespaceManager(reader.NameTable);
nsmanager.AddNamespace("ns2", "http://www.zadrwan.com/services/");
while (reader.Read())
{
switch (reader.Name)
{
case "ns2:Response":
Console.WriteLine(reader.Name);
Console.WriteLine(reader.ReadInnerXml());
break;
}
}
}