0

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 = response.executeSQLQueryResponse1.@return.Cast<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

Mohammed Sajid
  • 4,778
  • 2
  • 15
  • 20
rizu
  • 1,047
  • 1
  • 12
  • 21
  • List objectts ca be returned. See complete list at : https://developer.cisco.com/docs/axl/#!what-is-axl/what-is-administrative-xml – jdweng Jun 13 '20 at 21:39
  • Why do you thing you are going to get XML? See following JAVA example for how to get XML https://developer.cisco.com/docs/axl/#!hello-world-with-java/hello-world-with-java Your code looks more like you are trying to retrieve data from a database then get a xml request/response. – jdweng Jun 13 '20 at 23:06
  • @jdweng this doesn't relate to my question, your response would further confuse others – rizu Jun 14 '20 at 15:35
  • Your request is wrong and not returning an xml. The java code shows the correct request to get an xml response. – jdweng Jun 14 '20 at 15:43
  • @jdweng, i think you need to take a look at this https://github.com/CiscoDevNet/axl-java-samples/blob/master/src/main/java/com/cisco/axlsamples/executeSqlQuery.java before stating a request is wrong ( and not adding relevant example), also you can answer the question, if you feel you have the answer – rizu Jun 14 '20 at 16:01
  • 1
    Not on that link indicates the request properties nor does the link say that xml is being returned. There is a binding that says xml (only a test case), but it will only work if the request properties asked for xml to be returned. – jdweng Jun 14 '20 at 16:45

1 Answers1

0

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;
David Staudt
  • 361
  • 2
  • 2