解析SOAP返回

时间:2017-05-09 20:43:08

标签: c# xml soap

好的,我知道有很多帖子,并且已经阅读了很多帖子,但我在代码中遗漏了一些东西,我只是看不出来。

作为一个背景故事,我试图解析思科电话系统的肥皂回报,我让它使用旧版本,但现在我无法获取它来提取我需要的数据。

这是我的代码:

    String xmlText = File.ReadAllText(@"c:\temp\IPAddress.xml");

    XmlDocument doc = new XmlDocument();
    XmlNamespaceManager nsmgr = new XmlNamespaceManager(doc.NameTable);

    nsmgr.AddNamespace("soapenv", "http://schemas.xmlsoap.org/soap/envelope/");
    nsmgr.AddNamespace("ns1", "http://schemas.cisco.com/ast/soap/");
    doc.LoadXml(xmlText);

    XmlNodeList items = doc.SelectNodes("/soapenv:Envelope/soapenv:Body/ns1:selectCmDeviceResponse/ns1:selectCmDeviceReturn/ns1:SelectCmDeviceResult/ns1:CmNodes/ns1:item/ns1:CmDevices/ns1:item", nsmgr);
    Console.WriteLine(doc.InnerText.ToString());
    foreach (XmlNode item in items)
    {
        string Name = GetNodeValue(item, "Name");
        string Description = GetNodeValue(item, "ns1:Description");
        string IpAddress = GetNodeValue(item, "ns1:IpAddress/ns1:item/ns1:IP");
        string DirNumber = GetNodeValue(item, "ns1:DirNumber");
        string Class = GetNodeValue(item, "ns1:DeviceClass");
        string Model = GetNodeValue(item, "ns1:Model");
        string Product = GetNodeValue(item, "ns1:Product");

        UpdateInfo(Name, IpAddress);
    }
}


Here is a snip of the XML:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
   <soapenv:Body>
      <ns1:selectCmDeviceResponse xmlns:ns1="http://schemas.cisco.com/ast/soap">
         <ns1:selectCmDeviceReturn>
            <ns1:SelectCmDeviceResult>
               <ns1:TotalDevicesFound>4</ns1:TotalDevicesFound>
               <ns1:CmNodes>
                  <ns1:item>
                     <ns1:ReturnCode>Ok</ns1:ReturnCode>
                     <ns1:Name>10.0.5.125</ns1:Name>
                     <ns1:NoChange>false</ns1:NoChange>
                     <ns1:CmDevices>
                        <ns1:item>
                           <ns1:Name>SEP1CE6C7729944</ns1:Name>
                           <ns1:DirNumber>4402-UnRegistered</ns1:DirNumber>
                           <ns1:DeviceClass>Phone</ns1:DeviceClass>
                           <ns1:Model>435</ns1:Model>
                           <ns1:Product>334</ns1:Product>
                           <ns1:BoxProduct>0</ns1:BoxProduct>
                           <ns1:Httpd>Yes</ns1:Httpd>
                           <ns1:RegistrationAttempts>0</ns1:RegistrationAttempts>
                           <ns1:IsCtiControllable>true</ns1:IsCtiControllable>
                           <ns1:LoginUserId>earlene.gonzalez</ns1:LoginUserId>
                           <ns1:Status>UnRegistered</ns1:Status>
                           <ns1:StatusReason>8</ns1:StatusReason>
                           <ns1:PerfMonObject>2</ns1:PerfMonObject>
                           <ns1:DChannel>0</ns1:DChannel>
                           <ns1:Description>105_GRN_LO-PH</ns1:Description>
                           <ns1:H323Trunk>
                              <ns1:ConfigName xsi:nil="1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
                              <ns1:TechPrefix xsi:nil="1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
                              <ns1:Zone xsi:nil="1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
                              <ns1:RemoteCmServer1 xsi:nil="1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
                              <ns1:RemoteCmServer2 xsi:nil="1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
                              <ns1:RemoteCmServer3 xsi:nil="1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
                              <ns1:AltGkList xsi:nil="1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
                              <ns1:ActiveGk xsi:nil="1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
                              <ns1:CallSignalAddr xsi:nil="1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
                              <ns1:RasAddr xsi:nil="1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
                           </ns1:H323Trunk>
                           <ns1:TimeStamp>1494272299</ns1:TimeStamp>
                           <ns1:Protocol>SCCP</ns1:Protocol>
                           <ns1:NumOfLines>1</ns1:NumOfLines>
                           <ns1:LinesStatus>
                              <ns1:item>
                                 <ns1:DirectoryNumber>4402</ns1:DirectoryNumber>
                                 <ns1:Status>UnRegistered</ns1:Status>
                              </ns1:item>
                           </ns1:LinesStatus>
                           <ns1:ActiveLoadID>SCCP45.9-4-2SR2-2S</ns1:ActiveLoadID>
                           <ns1:InactiveLoadID xsi:nil="1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
                           <ns1:DownloadStatus>Unknown</ns1:DownloadStatus>
                           <ns1:DownloadFailureReason xsi:nil="1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
                           <ns1:DownloadServer xsi:nil="1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
                           <ns1:IPAddress>
                              <ns1:item>
                                 <ns1:IP>10.105.2.55</ns1:IP>
                                 <ns1:IPAddrType>ipv4</ns1:IPAddrType>
                                 <ns1:Attribute>AdministrativeAndSignaling</ns1:Attribute>
                              </ns1:item>
                           </ns1:IPAddress>
                        </ns1:item>
                        <ns1:item>
                           <ns1:Name>SEP1CE6C772F3FB</ns1:Name>
                           <ns1:DirNumber xsi:nil="1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
                           <ns1:DeviceClass>Phone</ns1:DeviceClass>
                           <ns1:Model>435</ns1:Model>
                           <ns1:Product>334</ns1:Product>
                           <ns1:BoxProduct>0</ns1:BoxProduct>
                           <ns1:Httpd>Yes</ns1:Httpd>
                           <ns1:RegistrationAttempts>1</ns1:RegistrationAttempts>
                           <ns1:IsCtiControllable>true</ns1:IsCtiControllable>
                           <ns1:LoginUserId xsi:nil="1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
                           <ns1:Status>Rejected</ns1:Status>
                           <ns1:StatusReason>27</ns1:StatusReason>
                           <ns1:PerfMonObject>0</ns1:PerfMonObject>
                           <ns1:DChannel>0</ns1:DChannel>
                           <ns1:Description xsi:nil="1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
                           <ns1:H323Trunk>
                              <ns1:ConfigName xsi:nil="1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
                              <ns1:TechPrefix xsi:nil="1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
                              <ns1:Zone xsi:nil="1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
                              <ns1:RemoteCmServer1 xsi:nil="1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
                              <ns1:RemoteCmServer2 xsi:nil="1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
                              <ns1:RemoteCmServer3 xsi:nil="1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
                              <ns1:AltGkList xsi:nil="1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
                              <ns1:ActiveGk xsi:nil="1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
                              <ns1:CallSignalAddr xsi:nil="1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
                              <ns1:RasAddr xsi:nil="1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
                           </ns1:H323Trunk>
                           <ns1:TimeStamp>1494335117</ns1:TimeStamp>
                           <ns1:Protocol>SCCP</ns1:Protocol>
                           <ns1:NumOfLines>0</ns1:NumOfLines>
                           <ns1:LinesStatus/>
                           <ns1:ActiveLoadID xsi:nil="1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
                           <ns1:InactiveLoadID xsi:nil="1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
                           <ns1:DownloadStatus>Unknown</ns1:DownloadStatus>
                           <ns1:DownloadFailureReason xsi:nil="1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
                           <ns1:DownloadServer xsi:nil="1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
                           <ns1:IPAddress>
                              <ns1:item>
                                 <ns1:IP>10.106.0.104</ns1:IP>
                                 <ns1:IPAddrType>ipv4</ns1:IPAddrType>
                                 <ns1:Attribute>AdministrativeAndSignaling</ns1:Attribute>
                              </ns1:item>
                           </ns1:IPAddress>
                        </ns1:item>
                     </ns1:CmDevices>
                  </ns1:item>
                  <ns1:item>
                     <ns1:ReturnCode>Ok</ns1:ReturnCode>
                     <ns1:Name>10.0.5.127</ns1:Name>
                     <ns1:NoChange>false</ns1:NoChange>
                     <ns1:CmDevices>
                        <ns1:item>
                           <ns1:Name>SEP04DAD2BF58D4</ns1:Name>
                           <ns1:DirNumber>5173-Registered</ns1:DirNumber>
                           <ns1:DeviceClass>Phone</ns1:DeviceClass>
                           <ns1:Model>435</ns1:Model>
                           <ns1:Product>334</ns1:Product>
                           <ns1:BoxProduct>0</ns1:BoxProduct>
                           <ns1:Httpd>Yes</ns1:Httpd>
                           <ns1:RegistrationAttempts>0</ns1:RegistrationAttempts>
                           <ns1:IsCtiControllable>true</ns1:IsCtiControllable>
                           <ns1:LoginUserId xsi:nil="1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
                           <ns1:Status>Registered</ns1:Status>
                           <ns1:StatusReason>0</ns1:StatusReason>
                           <ns1:PerfMonObject>2</ns1:PerfMonObject>
                           <ns1:DChannel>0</ns1:DChannel>
                           <ns1:Description>114_BEL_CR-PH</ns1:Description>
                           <ns1:H323Trunk>
                              <ns1:ConfigName xsi:nil="1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
                              <ns1:TechPrefix xsi:nil="1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
                              <ns1:Zone xsi:nil="1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
                              <ns1:RemoteCmServer1 xsi:nil="1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
                              <ns1:RemoteCmServer2 xsi:nil="1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
                              <ns1:RemoteCmServer3 xsi:nil="1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
                              <ns1:AltGkList xsi:nil="1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
                              <ns1:ActiveGk xsi:nil="1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
                              <ns1:CallSignalAddr xsi:nil="1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
                              <ns1:RasAddr xsi:nil="1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
                           </ns1:H323Trunk>
                           <ns1:TimeStamp>1494105234</ns1:TimeStamp>
                           <ns1:Protocol>SCCP</ns1:Protocol>
                           <ns1:NumOfLines>1</ns1:NumOfLines>
                           <ns1:LinesStatus>
                              <ns1:item>
                                 <ns1:DirectoryNumber>5173</ns1:DirectoryNumber>
                                 <ns1:Status>Registered</ns1:Status>
                              </ns1:item>
                           </ns1:LinesStatus>
                           <ns1:ActiveLoadID>SCCP45.9-4-2SR2-2S</ns1:ActiveLoadID>
                           <ns1:InactiveLoadID xsi:nil="1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
                           <ns1:DownloadStatus>Unknown</ns1:DownloadStatus>
                           <ns1:DownloadFailureReason xsi:nil="1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
                           <ns1:DownloadServer xsi:nil="1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
                           <ns1:IPAddress>
                              <ns1:item>
                                 <ns1:IP>10.114.2.14</ns1:IP>
                                 <ns1:IPAddrType>ipv4</ns1:IPAddrType>
                                 <ns1:Attribute>AdministrativeAndSignaling</ns1:Attribute>
                              </ns1:item>
                           </ns1:IPAddress>
                        </ns1:item>
                        <ns1:item>
                           <ns1:Name>SEP04DAD2BF6F3D</ns1:Name>
                           <ns1:DirNumber>8001-Registered</ns1:DirNumber>
                           <ns1:DeviceClass>Phone</ns1:DeviceClass>
                           <ns1:Model>435</ns1:Model>
                           <ns1:Product>334</ns1:Product>
                           <ns1:BoxProduct>0</ns1:BoxProduct>
                           <ns1:Httpd>Yes</ns1:Httpd>
                           <ns1:RegistrationAttempts>0</ns1:RegistrationAttempts>
                           <ns1:IsCtiControllable>true</ns1:IsCtiControllable>
                           <ns1:LoginUserId xsi:nil="1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
                           <ns1:Status>Registered</ns1:Status>
                           <ns1:StatusReason>0</ns1:StatusReason>
                           <ns1:PerfMonObject>2</ns1:PerfMonObject>
                           <ns1:DChannel>0</ns1:DChannel>
                           <ns1:Description>115_MCD_PHN</ns1:Description>
                           <ns1:H323Trunk>
                              <ns1:ConfigName xsi:nil="1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
                              <ns1:TechPrefix xsi:nil="1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
                              <ns1:Zone xsi:nil="1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
                              <ns1:RemoteCmServer1 xsi:nil="1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
                              <ns1:RemoteCmServer2 xsi:nil="1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
                              <ns1:RemoteCmServer3 xsi:nil="1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
                              <ns1:AltGkList xsi:nil="1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
                              <ns1:ActiveGk xsi:nil="1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
                              <ns1:CallSignalAddr xsi:nil="1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
                              <ns1:RasAddr xsi:nil="1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
                           </ns1:H323Trunk>
                           <ns1:TimeStamp>1494259757</ns1:TimeStamp>
                           <ns1:Protocol>SCCP</ns1:Protocol>
                           <ns1:NumOfLines>1</ns1:NumOfLines>
                           <ns1:LinesStatus>
                              <ns1:item>
                                 <ns1:DirectoryNumber>8001</ns1:DirectoryNumber>
                                 <ns1:Status>Registered</ns1:Status>
                              </ns1:item>
                           </ns1:LinesStatus>
                           <ns1:ActiveLoadID>SCCP45.9-4-2SR2-2S</ns1:ActiveLoadID>
                           <ns1:InactiveLoadID xsi:nil="1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
                           <ns1:DownloadStatus>Unknown</ns1:DownloadStatus>
                           <ns1:DownloadFailureReason xsi:nil="1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
                           <ns1:DownloadServer xsi:nil="1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
                           <ns1:IPAddress>
                              <ns1:item>
                                 <ns1:IP>10.115.2.18</ns1:IP>
                                 <ns1:IPAddrType>ipv4</ns1:IPAddrType>
                                 <ns1:Attribute>AdministrativeAndSignaling</ns1:Attribute>
                              </ns1:item>
                           </ns1:IPAddress>
                        </ns1:item>
                     </ns1:CmDevices>
                  </ns1:item>
                  <ns1:item>
                     <ns1:ReturnCode>NotFound</ns1:ReturnCode>
                     <ns1:Name>10.0.5.128</ns1:Name>
                     <ns1:NoChange>true</ns1:NoChange>
                     <ns1:CmDevices xsi:nil="1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
                  </ns1:item>
               </ns1:CmNodes>
            </ns1:SelectCmDeviceResult>
            <ns1:StateInfo>&lt;StateInfo>&lt;Node Name="10.0.5.125" SubsystemStartTime="1492659312" StateId="1478" TotalItemsFound="20" TotalItemsReturned="2"/>&lt;Node Name="10.0.5.127" SubsystemStartTime="1492661102" StateId="5649" TotalItemsFound="232" TotalItemsReturned="2"/>&lt;Node Name="10.0.5.128" SubsystemStartTime="0" StateId="0" TotalItemsFound="0" TotalItemsReturned="0"/>&lt;/StateInfo></ns1:StateInfo>
         </ns1:selectCmDeviceReturn>
      </ns1:selectCmDeviceResponse>
   </soapenv:Body>
</soapenv:Envelope>

1 个答案:

答案 0 :(得分:0)

您忘记了NameN的GetNodeValue中的命名空间前缀。这是否会以某种方式弄乱你正在处理数据的其余部分?