2017-05-09 84 views
0

好吧,我知道有很多帖子,并阅读了很多,但我错过了我的代码中的东西,我只是不能看到什么。作为背后的故事,我试图从思科电话系统解析肥皂返回,我使用它的旧版本,但现在我无法获取它来提取我需要的数据。解析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> 
+0

什么不行? XmlNodeList是空还是GetNodeValue不返回任何内容?如果是后者,我们也需要该代码。 – rene

+0

老实说不清楚,我想清单。我今天砍了这么长时间,有一点,items变量是空的,所以我只是假设列表 – Bryant

+0

好吧,我想更进一步,我删除了cisco命名空间中的尾部斜线,奇怪,但现在我的列表有信息,但是在项目的返回node.InnerText上得到一个NullReferenceException。 – Bryant

回答

0

你忘了命名空间前缀GetNodeValue的名称。这是不是在搞乱你对数据做的其他事情?

+0

是的,我认为这是其中的一部分,我还为SelectSingleNode添加了一个名称空间给GetValueNode,但我仍然在IP上轰炸,这里是一个修订: – Bryant

+0

对不起,没有在外观注释中发布更多代码太长 – Bryant

+0

作为一个测试,我将一个虚拟值插入IpAddress,它工作,所以我剩下提取IP字符串IpAddress = GetNodeValue(item,“ns1:IpAddress/ns1:item/ns1:IP”,nsmgr);'不像名称那样工作。 – Bryant