CUCM axl api returns system.object when i try to query using ExecuteQueryReq

388 views Asked by At

When i try to return data from CUCM AXL api, using the code below

 ExecuteSQLQueryReq query = new ExecuteSQLQueryReq();

        query.sql = "select  * from systables ";

        string[] model = null;
        //get tables

        try
        {       
            executeSQLQueryResponse response = await client.executeSQLQueryAsync(query);

            model = [email protected]<string>().ToArray();               
        }
        catch (Exception ex)
        {
            Console.WriteLine($"\nError: getQuery: { ex.Message }");
            Environment.Exit(-1);
        }

        Console.WriteLine($"\ngetQuery: SUCCESS  model: { model }\n ");

i get sytem.object[] instead of the sql data, i have tried looping from each data using the code below

foreach ( string no in model)
{
    Console.WriteLine(no.ToString());
}

error i get is :

Unable to cast object of type 'System.Xml.XmlNode[]' to type 'System.String'.

is there a way to get the data returned without the back and forth conversion

I have been following the example here

any help would be appreciated

1

There are 1 answers

0
David Staudt On

The trick should be to cast return/rows as 'ElementNSImpl', e.g. as shown in the referenced sample at https://github.com/CiscoDevNet/axl-dotnet-samples:

ExecuteSQLQueryReq query = new ExecuteSQLQueryReq();

// Set the text of the SQL query
query.setSql( "select name, pkid from applicationuser" );

// We'll use this list to receive the rows returned by the query
List<Object> user_list = null;

try {
    // Prepare a ExecuteSQLQueryRes object to receive the response from AXL
    ExecuteSQLQueryRes resp = axlPort.executeSQLQuery( query );

    // getRow() returns all of the rows as a List<Object> type
    user_list = resp.getReturn().getRow();

} catch ( Exception e ) {

}

// Create an iterator to cycle through each row, below
Iterator<Object> itr = user_list.iterator();

// While the iterator indicates there is at least one more row...
while ( itr.hasNext() ) {

    // The individual row object is of this ElementNSImpl type - we'll need to cast from generic Object here
    ElementNSImpl el = ( ElementNSImpl )itr.next();

    // Print out the formatted name and pkid values
    System.out.println(
        "Name: " + String.format( "%-20s", el.getElementsByTagName( "name" ).item( 0 ).getTextContent() )+
        " PKID: " + el.getElementsByTagName( "pkid" ).item( 0 ).getTextContent() );
}

Though note the sample is based on Oracle Java 1.8, using the same version to generate code from WSDL via wsimport, and to parse the result:

com.sun.org.apache.xerces.internal.dom.ElementNSImpl;