2 Replies Latest reply on Jul 22, 2013 4:21 AM by Korey Hubbard

    Problems with QueryXml when using a more complex query with multiple tables in c# from CSClient

    Korey Hubbard

      I am trying to modify the CSClient code that is provided in the SDK to fetch data via QueryXml with more than one table in the query.

      The problem I am having is when I try include another table data I get this error " An unhandled exception of type 'System.NullReferenceException' occurred in CSClient.exe Additional information: Object reference not set to an instance of an object." What is the best way to fetch data based on my query so I can select individual nodes such as "alert.NodeID"  I am wanting to pull the data and insert it into a local MySQL database you see.


      Any help or advice would be appreciated.


      static void Main()


                  const string hostname = "";

                  const string username = "";

                  const string password = "";


                  ServicePointManager.ServerCertificateValidationCallback = (sender, certificate, chain, errors) => true;


                  var client = new InformationServiceClient("BasicHttpBinding_InformationService",

                                                            string.Format("https://{0}:17778/SolarWinds/InformationService/OrionBasic", hostname));

                  client.ClientCredentials.UserName.UserName = username;

                  client.ClientCredentials.UserName.Password = password;



                  var result = client.QueryXml("SELECT Interfaces.FullName, Interfaces.NodeID, Nodes.IPAddress FROM Orion.NPM.Interfaces INNER JOIN Orion.Nodes ON Interfaces.NodeID = Nodes.NodeID WHERE Interfaces.Status <> '1' RETURN XML AUTO", null);


                  var element = result.XPathSelectElement("//*[local-name()='Interfaces']");

                  var element2 = result.XPathSelectElement("//*[local-name()='Nodes']");


                  var alert = new AlertInfo


                      FullName = element.ElementAnyNS("FullName").Value,

                      NodeID = element.ElementAnyNS("NodeID").Value,

                      IPAddress = element2.ElementAnyNS("IPAddress").Value,



                  var alerts = new[] {alert};


                  var dcs = new DataContractSerializer(alerts.GetType());

                  var doc = new XmlDocument();

                  using (var writer = doc.CreateNavigator().AppendChild())


                      dcs.WriteObject(writer, alerts);




                  var arguments = new ArrayOfXmlElement {XDocument.Load(new XmlNodeReader(doc)).Root};

                  var result2 = client.Invoke("Orion.AlertStatus", "Acknowledge", arguments);



                  Console.WriteLine("FullName: " + alert.FullName);

                  Console.WriteLine("NodeID: " + alert.NodeID);

                  Console.WriteLine("IPAddress: " + alert.IPAddress);






              [DataContract(Name = "AlertInfo", Namespace = "http://schemas.solarwinds.com/2008/Orion")]

              public class AlertInfo


                  [DataMember(Order = 1)]

                  public string FullName;


                  [DataMember(Order = 2)]

                  public string NodeID;


                  [DataMember(Order = 3)]

                  public string IPAddress;