REST .NET Example 1: Retrieving the list of accounts for an authenticated user
(Return to main article: Samples for .NET (REST) v1)
1. Specify service URL:
private const string serviceURL = "http://server[:port]/services/v1/adminservice/accounts/";
2. Provide login information:
private const string login = "YOUR_LOGIN"; private const string password = "YOUR_PASSWORD";
3. Compose the REST URL:
string url = serviceURL + "?login=" + login + "&password=" + password;
4. Retrieve account list:
XPathDocument xPathDocument = new XPathDocument(url);
5. Parse response:
XPathNavigator xPathNavigator = xPathDocument.CreateNavigator(); XmlNameTable xmlNameTable = new NameTable(); XmlNamespaceManager xmlNamespaceManager = new XmlNamespaceManager(xmlNameTable); xmlNamespaceManager.AddNamespace("tns", "https://urchin.com/api/urchin/v1/"); XPathNodeIterator accountXPathNodeIterator = xPathNavigator.Select("/tns:getAccountListResponse/account", xmlNamespaceManager);
6. Display the information about retrieved accounts:
while (accountXPathNodeIterator.MoveNext()) DisplayAccount(accountXPathNodeIterator.Current); ... // Function to display account info. private static void DisplayAccount(XPathNavigator accountXPathNavigator) { Console.Write("Account id is \"" + accountXPathNavigator.SelectSingleNode("accountId/text()") + "\", "); Console.Write("name is \"" + accountXPathNavigator.SelectSingleNode("accountName/text()") + "\", "); Console.Write("contact name is \"" + accountXPathNavigator.SelectSingleNode("contactName/text()") + "\", "); Console.Write("e-mail is \"" + accountXPathNavigator.SelectSingleNode("emailAddress/text()") + "\" "); Console.WriteLine("and phone number is \"" + accountXPathNavigator.SelectSingleNode("phoneNumber/text()") + "\"."); }
Complete sample code for this example is available in the AdminServiceGetAccountListREST.cs file.
(Return to main article: Samples for .NET (REST) v1)