【问题标题】:CUCM axl api returns system.object when i try to query using ExecuteQueryReq当我尝试使用 ExecuteQueryReq 查询时,CUCM axl api 返回 system.object
【发布时间】:2020-06-13 21:01:50
【问题描述】:

当我尝试使用以下代码从 CUCM AXL api 返回数据时

 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 ");

我得到的是 sytem.object[] 而不是 sql 数据,我尝试使用下面的代码从每个数据循环

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

我得到的错误是:

无法将“System.Xml.XmlNode[]”类型的对象转换为“System.String”类型。

有没有办法不用来回转换就可以得到返回的数据

我一直在关注here的例子

任何帮助将不胜感激

【问题讨论】:

  • 可以返回列表对象。查看完整列表:developer.cisco.com/docs/axl/#!what-is-axl/…
  • 你为什么要获得 XML?请参阅以下 JAVA 示例了解如何获取 XML developer.cisco.com/docs/axl/#!hello-world-with-java/… 您的代码看起来更像是您试图从数据库中检索数据然后获取 xml 请求/响应。
  • @jdweng 这与我的问题无关,您的回答会进一步混淆其他人
  • 您的请求有误,没有返回 xml。 Java 代码显示了获取 xml 响应的正确请求。
  • 该链接上没有表示请求属性,也没有表示正在返回 xml。有一个绑定说 xml(只是一个测试用例),但它只有在请求属性要求返回 xml 时才有效。

标签: c# xml cisco cisco-axl


【解决方案1】:

诀窍应该是将 return/rows 转换为 'ElementNSImpl',例如如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() );
}

虽然请注意示例基于 Oracle Java 1.8,使用相同版本通过 wsimport 从 WSDL 生成代码,并解析结果:

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

【讨论】:

    猜你喜欢
    • 2016-02-04
    • 2018-12-25
    • 1970-01-01
    • 2020-01-13
    • 2021-12-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多