using System;
using System.Xml;
using System.Net;
using System.IO;
using System.Security.Cryptography;
/// <summary>
///--------------------------------------------------------------------------------------------------------
/// .NET C# implementation of Anveo API to initiate DIAL.CONNECT API function
///
/// The rest of Anveo API functions can be implemented by simply changing XML stored in $data variable
/// 2008 - Anveo team.
///--------------------------------------------------------------------------------------------------------
/// </summary>
Public static string GetSignature(String email, String passphrase) {
var enc = Encoding.ASCII;
HMACSHA1 hmac = new HMACSHA1(enc.GetBytes(passphrase));
hmac.Initialize();
byte[] buffer = enc.GetBytes(email);
return BitConverter.ToString(hmac.ComputeHash(buffer)).Replace("-", "").ToLower();
}
public static XmlDocument doApiCall(String sApiXML)
{
//Declare XMLResponse document
XmlDocument XMLResponse = null;
//Declare an HTTP-specific implementation of the WebRequest class.
HttpWebRequest objHttpWebRequest;
//Declare an HTTP-specific implementation of the WebResponse class
HttpWebResponse objHttpWebResponse = null;
//Declare a generic view of a sequence of bytes
Stream objRequestStream = null;
Stream objResponseStream = null;
//Declare XMLReader
XmlTextReader objXMLReader;
//Creates an HttpWebRequest for the Anveo API URL.
objHttpWebRequest = (HttpWebRequest)WebRequest.Create("https://www.anveo.com/api/v3.asp");
try
{
//---------- ANVEO API HttpRequest
//Prepare HttpWebRequest properties
byte[] bytes;
bytes = System.Text.Encoding.ASCII.GetBytes(sApiXML);
objHttpWebRequest.Method = "POST";
objHttpWebRequest.ContentLength = bytes.Length;
objHttpWebRequest.ContentType = "application/xml; encoding='utf-8'";
objHttpWebRequest.Accept="application/xml; encoding='utf-8'";
//Get Stream object
objRequestStream = objHttpWebRequest.GetRequestStream();
//Writes a sequence of bytes to the current stream
objRequestStream.Write(bytes, 0, bytes.Length);
//Close stream
objRequestStream.Close();
//Send and wait for a response.
objHttpWebResponse = (HttpWebResponse)objHttpWebRequest.GetResponse();
//---------- End ANVEO API HttpRequest
//---------- ANVEO API HttpResponse
if (objHttpWebResponse.StatusCode == HttpStatusCode.OK)
{
//Get response stream
objResponseStream = objHttpWebResponse.GetResponseStream();
//Load response stream into XMLReader
objXMLReader = new XmlTextReader(objResponseStream);
//Declare XMLDocument
XmlDocument xmldoc = new XmlDocument();
xmldoc.Load(objXMLReader);
//Set XMLResponse object returned from XMLReader
XMLResponse = xmldoc;
//Close XMLReader
objXMLReader.Close();
}
//Close HttpWebResponse
objHttpWebResponse.Close();
}
catch (WebException we)
{
//TODO: Add exception handling
throw new Exception(we.Message);
}
catch (Exception ex)
{
throw new Exception(ex.Message);
}
finally
{
//Close connections
objRequestStream.Close();
objResponseStream.Close();
objHttpWebResponse.Close();
}
return XMLResponse;
}