06-22-2015 05:06 AM
Hi all
Please can any one helps me with put axl response int to dataGridview.
I'm able do put one Item is datagridview.
What I want is to <name>SEP000000001234</name> and <userid>ABUser1</userid> in to datagridview.
Herby my code:
private void getdevbyuserid() | |
{ | |
//string version = Properties.Settings.Default.CUCMVersion; |
string version = "7.1"; | |
string strDevicePhone; |
string soap = "<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:ns=\"http://www.cisco.com/AXL/API/7.1\">\n"; | |
soap += "<soapenv:Header/>\n"; | |
soap += "<soapenv:Body>\n"; | |
soap += "<ns:executeSQLQuery sequence=\"1\">\n"; | |
soap += "<sql>select d.name, eu.userid from extensionmobilitydynamic emd, device d, device p, enduser eu where emd.fkdevice=d.pkid and emd.fkdevice_currentloginprofile=p.pkid and emd.fkenduser=eu.pkid </sql>\n"; | |
soap += "</ns:executeSQLQuery>\n"; | |
soap += "</soapenv:Body>\n"; | |
soap += "</soapenv:Envelope>\n"; |
Logging.Text += "---------|AXL Request|---------\n\n"; | |
Logging.Text += soap + "\n\n"; |
#region AXL SOAP | |
try | |
{ | |
byte[] soapBytes = Encoding.UTF8.GetBytes(soap); |
ServicePointManager.ServerCertificateValidationCallback += delegate { return true; }; | |
HttpWebRequest httpRQ = (HttpWebRequest)HttpWebRequest.Create(string.Format(@"https://151.184.162.10:8443/axl/")); |
httpRQ.ProtocolVersion = System.Net.HttpVersion.Version10; | |
httpRQ.Credentials = new NetworkCredential("user1", "password1");//Callmanager gebruikersnaam / password | |
httpRQ.Method = "POST"; | |
httpRQ.ContentType = "text/xml; charset=utf-8"; | |
httpRQ.Accept = "text/xml"; | |
httpRQ.Headers.Add("SOAPAction: 'CUCM:DB ver=" + version + "'"); | |
httpRQ.ContentLength = soapBytes.Length; |
//Send the xml soap to cucm | |
Stream stm = httpRQ.GetRequestStream(); | |
stm.Write(soapBytes, 0, soapBytes.Length); | |
stm.Close(); |
//Build the xml response | |
XDocument responcedoc = new XDocument(); | |
HttpWebResponse responce = httpRQ.GetResponse() as HttpWebResponse; | |
Stream responcedata = responce.GetResponseStream(); | |
StreamReader responsereader = new StreamReader(responcedata); | |
Logging.Text += "\n---------|AXL Response|---------\n\n"; | |
XDocument respdoc = XDocument.Load(responsereader); | |
Logging.Text += respdoc + "\n"; | |
soap = null; |
//fill in the combo |
//DevicePhone.Items.Clear(); |
//foreach (XElement item in respdoc.Descendants("name")) | |
foreach (XElement item in respdoc.Descendants("userid")) | |
{ | |
//cucmgrouplist.Items.Add((string)item); | |
//DevicePhone.Items.Add((string)item); | |
strDevicePhone = ((string)item); | |
//txtDevMac.Text = strDN1; | |
label3.Text = strDevicePhone; | |
DataTable jmn = new DataTable("respdoc"); | |
try | |
{ |
jmn.Columns.Add("name"); | |
jmn.Columns.Add("userid"); |
DataRow row1 = null; |
row1 = jmn.NewRow(); | |
row1["name"] = ((string)item); | |
//row1["userid"] = respdoc.Descendants("userid").ToString; |
jmn.Rows.Add(row1); |
dataGridView1.DataSource = jmn; |
} | |
catch (Exception ex) | |
{ | |
//Interaction.MsgBox(ex.ToString()); | |
} |
} | |
} | |
catch (Exception ex) | |
{ | |
Logging.Text += "\n"; | |
Logging.Text += "\n---------|AXL Error|---------\n\n"; | |
Logging.Text += string.Format("\n" + DateTime.Now + ":: ERROR :: Message: {0}\n", ex.Message); | |
} |
#endregion | |
} Thanks in advanced Regards Jan Meeling |
06-22-2015 06:34 AM
This looks more like a C# question than an AXL question. Perhaps there's a C# developers forum on the net? Stack Overflow is also a good place to post a question like this.
06-22-2015 09:32 AM
HI Nicholas,
this more a axl problem c# is the language i'm programing in.
I'm be able ro put one item in the datagrifview but now the rest of axl info.
I'm also bussy with outer board.
thanks.
regards
jan meeling
06-22-2015 10:40 AM
Well, I'm not a C# guy, but my first impression is that you're descending the XML tree the wrong way.
Here's an example of what your query might return:
<return>
<row>
<name>SEP01010101010101</name>
<userid>waffle</userid>
</row>
<row>
<name>SEP01010101010102</name>
<userid>wiffle</userid>
</row>
<return>
I'm modifying my response because I looked into C# a bit. This line means you're going to iterate through the entire XML document, finding each "userid".
foreach (XElement item in respdoc.Descendants("userid"))
I would think you want to do a foreach on the document descendants "row", then find the sub-elements "name" and "userid" in each occurrence.
06-22-2015 10:40 PM
HI Nicholas,
Thanks for your response.
The problem that I have now is as follows:
I get it in the datagridview but only the last record but when I put the data to combox It get the complete list.
Do you have a Idee.
Thanks.
Regards,
Jan
06-23-2015 08:42 AM
Again, that's a C# and Microsoft SDK issue, and I'm not a C# guy, so I have no idea how C# and the dotNet API handles datagrid and comboboxes.
Discover and save your favorite ideas. Come back to expert answers, step-by-step guides, recent topics, and more.
New here? Get started with these tips. How to use Community New member guide