<?xml version="1.0" encoding="UTF-8"?>
<feed xmlns="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <title>UCS XML API in C#</title>
  <link rel="alternate" href="http://developer.cisco.com/c/message_boards/find_thread?p_l_id=&amp;threadId=8598300" />
  <subtitle>UCS XML API in C#</subtitle>
  <id>http://developer.cisco.com/c/message_boards/find_thread?p_l_id=&amp;threadId=8598300</id>
  <updated>2013-06-18T21:58:37Z</updated>
  <dc:date>2013-06-18T21:58:37Z</dc:date>
  <entry>
    <title>Automatic reply: New Message from Muhammad Afzal in Unified Computing UCS M</title>
    <link rel="alternate" href="http://developer.cisco.com/c/message_boards/find_message?p_l_id=&amp;messageId=8597630" />
    <author>
      <name>John Kennedy</name>
    </author>
    <id>http://developer.cisco.com/c/message_boards/find_message?p_l_id=&amp;messageId=8597630</id>
    <updated>2012-11-15T23:11:48Z</updated>
    <published>2012-11-15T23:11:48Z</published>
    <summary type="html">I am out of the office until the 20th of November, 2012. For FlexPod issues, please contact Arun Garg (arung@cisco.com&lt;https://mail.cisco.com/ecp/Organize/arung@cisco.com&gt;) or Chris O'Brien (chrobrie@cisco.com). Thanks for your patience - JFK</summary>
    <dc:creator>John Kennedy</dc:creator>
    <dc:date>2012-11-15T23:11:48Z</dc:date>
  </entry>
  <entry>
    <title>UCS XML API in C#</title>
    <link rel="alternate" href="http://developer.cisco.com/c/message_boards/find_message?p_l_id=&amp;messageId=8598299" />
    <author>
      <name>Muhammad Afzal</name>
    </author>
    <id>http://developer.cisco.com/c/message_boards/find_message?p_l_id=&amp;messageId=8598299</id>
    <updated>2012-11-16T01:08:55Z</updated>
    <published>2012-11-15T23:03:31Z</published>
    <summary type="html">While looking into UCS XML API documentation, I wrote a simple c# code as a test to consume UCS XML API in c# console application. I thought it would be worth sharing. 
 
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net;
using System.IO; 
using System.Xml;
 
 
 
namespace UCSAPIConsoleApp {
    class Program
    {
        static void Main(string[] args)
        {
 
            string sAuthCookie, sUsername, sPassword, sURI;
 
            try
            {
 
                Console.Write("Enter UCS URI(http:///nuova: ");
                sURI = Console.ReadLine();
 
                Console.Write("Enter username: ");
                sUsername = Console.ReadLine();
 
                Console.Write("Enter password: ");
                sPassword = Console.ReadLine();
 
                XmlDocument doc = new XmlDocument();
 
                doc.LoadXml(HTTPRequestResponse(sURI, ""));
                XmlNode xmln = doc.SelectSingleNode("/aaaLogin");
                sAuthCookie = xmln.Attributes["outCookie"].Value.ToString();
 
                Console.WriteLine("Auth Cookie:{0}", sAuthCookie);
                Console.WriteLine("=============================================================");
 
                doc.LoadXml(HTTPRequestResponse(sURI, ""));
 
                xmln = doc.SelectSingleNode("/configResolveDn/outConfig/computeBlade");
 
                for (int i = 0; i &lt; xmln.Attributes.Count; i++)
                    Console.WriteLine("{0}={1}", xmln.Attributes[i].Name, xmln.Attributes[i].Value);
 
                doc.LoadXml(HTTPRequestResponse(sURI, ""));
                xmln = doc.SelectSingleNode("/aaaLogout");
 
                Console.WriteLine("=============================================================");
                Console.WriteLine("Logout={0}", xmln.Attributes["outStatus"].Value.ToString());
 
                Console.ReadKey();
 
            }
            catch (Exception ex)
            {
                Console.WriteLine("Error occurred while execution:{0}", ex.Message);
            }
        }
 
 
 
 
        private static string HTTPRequestResponse(string sURL, string strXML)
        {
            byte[] XMLbuffer = Encoding.UTF8.GetBytes(strXML);
 
            try
            {
 
                HttpWebRequest WebReq = (HttpWebRequest)WebRequest.Create(sURL);
 
                WebReq.Method = "POST";
 
                WebReq.ContentType = "text/xml";
 
                WebReq.ContentLength = XMLbuffer.Length;
 
                Stream PostData = WebReq.GetRequestStream();
 
                PostData.Write(XMLbuffer, 0, XMLbuffer.Length);
                PostData.Close();
 
                using (HttpWebResponse WebResponse = (HttpWebResponse)WebReq.GetResponse())
                {
 
                    Stream response = WebResponse.GetResponseStream();
 
                    return new StreamReader(response).ReadToEnd();
                }
 
            }
            catch(Exception ex)
            {
                Console.WriteLine("Exception occurred: {0}", ex.Message);
                return null;
 
            }
 
 
        } 
 
 
    }
}
 
 
OUTPUT:
 
 
Auth Cookie:1353028019/a171253a-ebeb-4b21-b01d-4b357b611cba
=============================================================
adminPower=policy
adminState=in-service
assignedToDn=org-root/ls-11
association=none
availability=unavailable
availableMemory=4096
chassisId=1
checkPoint=discovered
connPath=A,B
connStatus=A,B
descr=
discovery=complete
dn=sys/chassis-1/blade-1
fltAggr=0
fsmDescr=
fsmFlags=
fsmPrev=DiscoverSuccess
fsmProgr=100
fsmRmtInvErrCode=none
fsmRmtInvErrDescr=
fsmRmtInvRslt=
fsmStageDescr=
fsmStamp=2012-11-16T01:51:21.487
fsmStatus=nop
fsmTry=0
intId=31838
lc=undiscovered
lcTs=1970-01-01T01:00:00.000
lowVoltageMemory=not-applicable
managingInst=A
memorySpeed=not-applicable
mfgTime=not-applicable
model=N20-B6620-1
name=
numOfAdaptors=1
numOfCores=6
numOfCoresEnabled=6
numOfCpus=1
numOfEthHostIfs=1
numOfFcHostIfs=0
numOfThreads=6
operPower=off
operQualifier=
operState=unassociated
operability=operable
originalUuid=1b4e28ba-2fa1-11d2-0101-b9a761bde3fb
presence=equipped
revision=0
serial=1045
serverId=1/1
slotId=1
totalMemory=4096
usrLbl=
uuid=1b4e28ba-2fa1-11d2-0101-b9a761bde3fb
vendor=Cisco Systems Inc
=============================================================
Logout=success</summary>
    <dc:creator>Muhammad Afzal</dc:creator>
    <dc:date>2012-11-15T23:03:31Z</dc:date>
  </entry>
</feed>

