当我尝试从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”类型。
是否有一种方法可以在不进行前后转换的情况下返回数据?
我一直在学习这里的例子
如能提供任何帮助,将不胜感激。
发布于 2020-06-17 22:04:44
诀窍应该是将返回/行转换为“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;https://stackoverflow.com/questions/62365510
复制相似问题