Software Development Kit (SDK) and API Discussions

HostListInfoIterNext .NET strange behavior

GEORGWERTHNER
2,041 Views

Hello,

I am using the code below to get a list of all hosts.

All commands execute successfully - meaning APIStatus equals "passed".

The HostListInfoIterStart returns the correct number of 10 records.

But when I invoke HostListInfoIterNext and set the Maximum member to 10 (see below), I get an InvalidOperationException in System.XML.dll.

If I dont set the Maximum member, then the exception is not thrown. But in HostListInfoIterNextResult the members Hosts and Records are null - allthough the APIStatus equals "passed".

I hope you can help me!

Thanks,

Georg

  NaDfm server = null;
  server = new NaDfm(_server);

  server.Credentials = new NetworkCredential(_user, _password);
  server.Protocol = ServerProtocol.HTTPS;
  server.Port = 8443;

  try
  {
        HostListInfoIterStart startInput = new HostListInfoIterStart();
        HostListInfoIterStartResult startOutput = startInput.Invoke(server);
        if (startOutput.APIStatus.Equals("passed"))
        {
              if (startOutput.Records.HasValue)
              {
                    HostListInfoIterNext nextInput = new HostListInfoIterNext();
                    nextInput.Tag = startOutput.Tag;
                    nextInput.Maximum = startOutput.Records;
                    HostListInfoIterNextResult nextOutput = nextInput.Invoke(server);

                    if (nextOutput.APIStatus.Equals("passed"))
                    {
     
                          HostInfo[] hostInfos = nextOutput.Hosts;
                          foreach (HostInfo info in hostInfos)
                          {
      
        
                          }
                    }
                    else
                    {
                          Debug.WriteLine("API Status: " + nextOutput.APIStatus);
                          Debug.WriteLine("Errno: " + nextOutput.Errno + " Failure Reason: " + nextOutput.FailureReason);
                    }
              }
              HostListInfoIterEnd endInput = new HostListInfoIterEnd();
              endInput.Tag = startOutput.Tag;
              HostListInfoIterEndResult endOutput = endInput.Invoke(server);
              if (endOutput.APIStatus.Equals("passed"))
              {
                    Debug.WriteLine("Stopped with iteration");
              }
              else
              {
                    Debug.WriteLine("API Status: " + endOutput.APIStatus);
                    Debug.WriteLine("Errno: " + endOutput.Errno + " Failure Reason: " + endOutput.FailureReason);
              }

        }
        else
        {
              Debug.WriteLine("API Status: " + startOutput.APIStatus);
              Debug.WriteLine("Errno: " + startOutput.Errno + " Failure Reason: " + startOutput.FailureReason);
        }


  }
  catch (NaException ne)
  {
        Debug.WriteLine("Exception: " + ne.Message);
  }
  catch (Exception e)
  {
        Debug.WriteLine("Exception: " + e.StackTrace);
  }

1 REPLY 1

GEORGWERTHNER
2,041 Views

I think that I have found the problem.

The InvalidOperationException is the result of System.FormatException thrown during Deserialization of the Server Response XML at System.Number.StringToNumber

I got the Server Response by calling HostListInforIterNext as follows:

HostListInfoIterNext nextInput = new HostListInfoIterNext();
nextInput.Tag = startOutput.Tag;
nextInput.Maximum = startOutput.Records;
System.Xml.XmlElement response = (System.Xml.XmlElement)server.Invoke(nextInput, typeof(System.Xml.XmlElement));

I assume that this xml Element is the problem:

<admin-port/>

The property HostInfo.AdminPort has the type int and not int?. So when the Server responds with an empty admin-port element the System.FormatException is thrown when trying to convert a Null Value to an int.

Public